package cn.iune.erp.sale;

import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;


import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.draw.LineSeparator;
import com.justep.baas.Utils;

import cn.iune.common.response.MapMessage;
import cn.iune.erp.customer.FileCustomer;
import cn.iune.erp.customer.IFileCustomerService;
import cn.iune.erp.inventory.FileItem;
import cn.iune.erp.inventory.FileStorage;
import cn.iune.erp.inventory.IFileItemService;
import cn.iune.erp.inventory.IFileStorageService;
import cn.iune.erp.inventory.IInventoryService;
import cn.iune.erp.inventory.IStorageItemService;
import cn.iune.erp.inventory.IStorageRecordDetailService;
import cn.iune.erp.inventory.IStorageRecordService;
import cn.iune.erp.inventory.StorageItem;
import cn.iune.erp.inventory.StorageRecord;
import cn.iune.erp.inventory.StorageRecordDetail;
import cn.iune.erp.setting.IParamSettingService;
import cn.iune.erp.setting.ISettingService;
import cn.iune.erp.setting.ParamSetting;


@Transactional
@Service
public class SaleServiceImpl implements ISaleService {
	
	Logger log = LogManager.getLogger(this.getClass());

	@Autowired
	private ISaleOrderService saleOrderService;
	@Autowired
	private ISaleOrderDetailService saleOrderDetailService;
	
	@Autowired
	private IFileCustomerService fileCustomerService;
	
	@Autowired
	private IFileItemService fileItemService;
	
	@Autowired
	private IFileStorageService fileStorageService;
	
	@Autowired
	private IStorageRecordService storageRecordService;
	@Autowired
	private IStorageRecordDetailService storageRecordDetailService;
	@Autowired
	private IStorageItemService storageItemService;
	
	@Autowired
	private IInventoryService inventoryService;
	
	
	@Autowired
	private IParamSettingService paramSettingService;
	
	@Autowired
	private ISettingService settingService;


	@Transactional
	private int doItOrderDetail(SaleOrderDetail s){
		//销售预测
		if (s.getOrigin()!=null 
			&& s.getOrigin().equals("XSYC") 
			&& s.getOriginNo()!=null 
			){
			//更新销售预测的订购数量
//			int updateResult = saleForecastDetailService.updatePickItemQuantity(s.getOriginNo(),s.getEnterpriseNo(),s.getItemAmount(), s.getPieceQuantity());
//			if (updateResult<0){
//				return -1;
//			}
		}
		
		return 0;
	}
	
	@Transactional
	private int unDoOrderDetail(SaleOrderDetail s){
		//销售预测
		if (s.getOrigin()!=null 
			&& s.getOrigin().equals("XSYC") 
			&& s.getOriginNo()!=null 
			){
			//更新销售预测的订购数量
//			int updateResult = saleForecastDetailService.updatePickItemQuantity(s.getOriginNo(),s.getEnterpriseNo(),s.getItemAmount().negate(), s.getPieceQuantity().negate());
//			if (updateResult<0){
//				return -1;
//			}
		}

		return 0;
	}

	@Override
	public Map<String,Object> saleOrderConfirm(String rowID){
		
		SaleOrder obj = saleOrderService.getByID(rowID);
		
		MapMessage mapMessage = new MapMessage(obj.getfID(),obj.getOrderNo(),obj.getBillType(),obj.getBillTypeName()
				,MapMessage.STATUSINFO_SUCCESS_CODE//"http://www.iune.cn"
				,MapMessage.STATUSINFO_SUCCESS_MSG//"操作成功！"
				,MapMessage.STATUSINFO_SUCCESS_INFO//"操作成功！"
				,MapMessage.STATUSINFO_SUCCESS_FLAG//"success"
				);
		
		String state = obj.getState();
		String audit = obj.getAudit();
		
		if(state.equals("active") && audit.equals("active")){
			//状态正常
		}else{
			mapMessage.setStatusCode("100001");
			mapMessage.setStatusMsg(MapMessage.STATUSINFO_FAILURE_MSG);
			mapMessage.setStatusInfo("单据状态有变化，请刷新后重试！");
			mapMessage.setStatusFlag(MapMessage.STATUSINFO_FAILURE_FLAG);
			//检查结果是否包括失败状态，如果包括，直接返回
			if (mapMessage.getStatusFlag().equals(MapMessage.STATUSINFO_FAILURE_FLAG)){
				return mapMessage.toMap();
			}
		}
		
		//提交之前产生运单
//		int isNeedLogistics = obj.getIsNeedLogistics();
//		if(isNeedLogistics==1) {
//			//送货上门
//			JSONObject json = logisticsService.waybillAdd(rowID, obj.getEmployeeNo(), obj.getEmployeeName(), obj.getcUsercode(), obj.getcUsername(), obj.getUserId());
//			int code = json.getIntValue("code");
//			if(code!=0) {
//				mapMessage.setStatusCode("100001");
//				mapMessage.setStatusMsg(MapMessage.STATUSINFO_FAILURE_MSG);
//				mapMessage.setStatusInfo("产生运单时发生了错误！");
//				mapMessage.setStatusFlag(MapMessage.STATUSINFO_FAILURE_FLAG);
//				return mapMessage.toMap();
//			}
//		}

		//首先审核从表
		saleOrderDetailService.confirmByMasterID(rowID);
		
		//然后审核主表
		saleOrderService.confirm(rowID);

		/*
		[
         {value:0,label:'0:不送审自动审核'}
         ,{value:1,label:'1:非工作流审签'}
         ,{value:2,label:'2:自由工作流审签'}
         ,{value:3,label:'3:工作流审签'}
         ];	
		*/
		
		if(obj.getFlowType()==0) {
			mapMessage.fromMap(this.saleOrderAgreeIt(rowID));
		}
		
		return mapMessage.toMap();
	}
	
	@Transactional
	@Override
	public Map<String,Object> saleOrderActive(String rowID){
		
		SaleOrder obj = saleOrderService.getByID(rowID);
		
		MapMessage mapMessage = new MapMessage(obj.getfID(),obj.getOrderNo(),obj.getBillType(),obj.getBillTypeName()
				,MapMessage.STATUSINFO_SUCCESS_CODE//"http://www.iune.cn"
				,MapMessage.STATUSINFO_SUCCESS_MSG//"操作成功！"
				,MapMessage.STATUSINFO_SUCCESS_INFO//"操作成功！"
				,MapMessage.STATUSINFO_SUCCESS_FLAG//"success"
				);
		
		String state = obj.getState();
		String audit = obj.getAudit();
		
		if(state.equals("confirm") && audit.equals("active")){
			//状态正常
		}else{
			mapMessage.setStatusCode("100001");
			mapMessage.setStatusMsg(MapMessage.STATUSINFO_FAILURE_MSG);
			mapMessage.setStatusInfo("单据状态有变化，请刷新后重试！");
			mapMessage.setStatusFlag(MapMessage.STATUSINFO_FAILURE_FLAG);
			//检查结果是否包括失败状态，如果包括，直接返回
			if (mapMessage.getStatusFlag().equals(MapMessage.STATUSINFO_FAILURE_FLAG)){
				return mapMessage.toMap();
			}
		}

		//首先审核从表
		saleOrderDetailService.activeByMasterID(rowID);
		
		//然后审核主表
		saleOrderService.active(rowID);
		
		//激活之后删除运单
//		int isNeedLogistics = obj.getIsNeedLogistics();
//		if(isNeedLogistics==1) {
//			//送货上门
//			JSONObject json = logisticsService.waybillDel(rowID);
//			int code = json.getIntValue("code");
//			if(code!=0) {
//				mapMessage.setStatusCode("100001");
//				mapMessage.setStatusMsg(MapMessage.STATUSINFO_FAILURE_MSG);
//				mapMessage.setStatusInfo("删除运单时发生了错误！");
//				mapMessage.setStatusFlag(MapMessage.STATUSINFO_FAILURE_FLAG);
//				return mapMessage.toMap();
//			}
//		}		
		
		return mapMessage.toMap();
	}
	
	@Transactional
	@Override
	public Map<String,Object> saleOrderAgreeIt(String rowID){
		//判断是否可以提交
		SaleOrder obj = saleOrderService.getByID(rowID);
		
//		List<SaleOrderDetail> objs = saleOrderDetailService.getByMasterID(rowID);
		
		MapMessage mapMessage = new MapMessage(obj.getfID(),obj.getOrderNo(),obj.getBillType(),obj.getBillTypeName()
				,MapMessage.STATUSINFO_SUCCESS_CODE//"http://www.iune.cn"
				,MapMessage.STATUSINFO_SUCCESS_MSG//"操作成功！"
				,MapMessage.STATUSINFO_SUCCESS_INFO//"操作成功！"
				,MapMessage.STATUSINFO_SUCCESS_FLAG//"success"
				);
		
		
		if("confirm".equals(obj.getAudit())){
			//已经审批
			return mapMessage.toMap();
		}
		
		//首先审核从表
//		saleOrderDetailService.agreeItByMasterID(rowID);
		List<SaleOrderDetail> sods = saleOrderDetailService.getByMasterID(rowID);
		for(SaleOrderDetail sod :sods){
			saleOrderDetailService.agreeIt(sod);
			this.doItOrderDetail(sod);
		}
		
		//然后审核主表
		saleOrderService.agreeIt(rowID);
		
		return mapMessage.toMap();

	}
	
	@Transactional
	@Override
	public Map<String,Object> saleOrderUnAgree(String rowID){
		//判断是否可以撤销
		SaleOrder obj = saleOrderService.getByID(rowID);
		
		List<SaleOrderDetail> objs = saleOrderDetailService.getByMasterID(rowID);
		
		MapMessage mapMessage = new MapMessage(obj.getfID(),obj.getOrderNo(),obj.getBillType(),obj.getBillTypeName()
				,MapMessage.STATUSINFO_SUCCESS_CODE//"http://www.iune.cn"
				,MapMessage.STATUSINFO_SUCCESS_MSG//"操作成功！"
				,MapMessage.STATUSINFO_SUCCESS_INFO//"操作成功！"
				,MapMessage.STATUSINFO_SUCCESS_FLAG//"success"
				);
		
		String state = obj.getState();
		String audit = obj.getAudit();
		
		if(state.equals("confirm") && audit.equals("confirm")){
			//状态正常
		}else{
			mapMessage.setStatusCode("100001");
			mapMessage.setStatusMsg(MapMessage.STATUSINFO_FAILURE_MSG);
			mapMessage.setStatusInfo("单据状态有变化，请刷新后重试！");
			mapMessage.setStatusFlag(MapMessage.STATUSINFO_FAILURE_FLAG);
			//检查结果是否包括失败状态，如果包括，直接返回
			if (mapMessage.getStatusFlag().equals(MapMessage.STATUSINFO_FAILURE_FLAG)){
				return mapMessage.toMap();
			}
		}
		
		if(obj.getBillType().equals("XSDD")){
			//首先判断主表
			//是否已经存在预付款，如果是则不能撤销
			if ("paid".equals(obj.getPaymentStatus())){
				mapMessage.setStatusCode("100001");
				mapMessage.setStatusMsg(MapMessage.STATUSINFO_FAILURE_MSG);
				mapMessage.setStatusInfo("单据有预付款，无法撤销审核！");
				mapMessage.setStatusFlag(MapMessage.STATUSINFO_FAILURE_FLAG);
			}
			//检查结果是否包括失败状态，如果包括，直接返回
			if (mapMessage.getStatusFlag().equals(MapMessage.STATUSINFO_FAILURE_FLAG)){
				return mapMessage.toMap();
			}

			//然后检查子表
			for(SaleOrderDetail o : objs){
				//判断是否已经下达工单
				/*
				if ("Y".equals(o.getPlaceOrder())){
					mapMessage.setStatusCode("100001");
					mapMessage.setStatusMsg(MapMessage.STATUSINFO_FAILURE_MSG);
					mapMessage.setStatusInfo("已下达工单，无法撤销审核！");
					mapMessage.setStatusFlag(MapMessage.STATUSINFO_FAILURE_FLAG);
				}
				*/
				//检查结果是否包括失败状态，如果包括，直接返回
				if (mapMessage.getStatusFlag().equals(MapMessage.STATUSINFO_FAILURE_FLAG)){
					return mapMessage.toMap();
				}

				//判断是否已经发货，或者正在发货
				if (o.getPickItemIng().compareTo(BigDecimal.ZERO)!=0 || o.getPickItemAmount().compareTo(BigDecimal.ZERO)!=0){
					mapMessage.setStatusCode("100001");
					mapMessage.setStatusMsg(MapMessage.STATUSINFO_FAILURE_MSG);
					mapMessage.setStatusInfo("单据已出库，无法撤销审核！");
					mapMessage.setStatusFlag(MapMessage.STATUSINFO_FAILURE_FLAG);
				}
				//检查结果是否包括失败状态，如果包括，直接返回
				if (mapMessage.getStatusFlag().equals(MapMessage.STATUSINFO_FAILURE_FLAG)){
					return mapMessage.toMap();
				}
			}
		}
		
		//首先执行子表
//		saleOrderDetailService.unAgreeByMasterID(rowID);
		List<SaleOrderDetail> sods = saleOrderDetailService.getByMasterID(rowID);
		for(SaleOrderDetail sod :sods){
			saleOrderDetailService.unAgree(sod);
			this.unDoOrderDetail(sod);
		}

		//然后审核主表
		saleOrderService.unAgree(rowID);
		
		
		return mapMessage.toMap();
	}
	
	@Transactional
	@Override
	public Map<String,Object> saleOrderClose(String rowID){
		
		SaleOrder obj = saleOrderService.getByID(rowID);
		
		MapMessage mapMessage = new MapMessage(obj.getfID(),obj.getOrderNo(),obj.getBillType(),obj.getBillTypeName()
				,MapMessage.STATUSINFO_SUCCESS_CODE//"http://www.iune.cn"
				,MapMessage.STATUSINFO_SUCCESS_MSG//"操作成功！"
				,MapMessage.STATUSINFO_SUCCESS_INFO//"操作成功！"
				,MapMessage.STATUSINFO_SUCCESS_FLAG//"success"
				);

		//首先审核从表
		int rtn = saleOrderDetailService.closeByMasterID(rowID);
		if (rtn != 0){
			mapMessage.setStatusCode(MapMessage.STATUSINFO_FAILURE_CODE);
			mapMessage.setStatusMsg(MapMessage.STATUSINFO_FAILURE_MSG);
			mapMessage.setStatusInfo(MapMessage.STATUSINFO_FAILURE_INFO);
			mapMessage.setStatusFlag(MapMessage.STATUSINFO_FAILURE_FLAG);
			return mapMessage.toMap();
		}
		
		//然后审核主表
		rtn = saleOrderService.close(rowID);
		if (rtn != 0){
			mapMessage.setStatusCode(MapMessage.STATUSINFO_FAILURE_CODE);
			mapMessage.setStatusMsg(MapMessage.STATUSINFO_FAILURE_MSG);
			mapMessage.setStatusInfo(MapMessage.STATUSINFO_FAILURE_INFO);
			mapMessage.setStatusFlag(MapMessage.STATUSINFO_FAILURE_FLAG);
			return mapMessage.toMap();
		}
		
		return mapMessage.toMap();
	}
	
	@Transactional
	@Override
	public Map<String,Object> saleOrderOpen(String rowID){
		
		SaleOrder obj = saleOrderService.getByID(rowID);
		
		MapMessage mapMessage = new MapMessage(obj.getfID(),obj.getOrderNo(),obj.getBillType(),obj.getBillTypeName()
				,MapMessage.STATUSINFO_SUCCESS_CODE//"http://www.iune.cn"
				,MapMessage.STATUSINFO_SUCCESS_MSG//"操作成功！"
				,MapMessage.STATUSINFO_SUCCESS_INFO//"操作成功！"
				,MapMessage.STATUSINFO_SUCCESS_FLAG//"success"
				);
		//首先审核从表
		int rtn = saleOrderDetailService.openByMasterID(rowID);
		if (rtn != 0){
			mapMessage.setStatusCode(MapMessage.STATUSINFO_FAILURE_CODE);
			mapMessage.setStatusMsg(MapMessage.STATUSINFO_FAILURE_MSG);
			mapMessage.setStatusInfo(MapMessage.STATUSINFO_FAILURE_INFO);
			mapMessage.setStatusFlag(MapMessage.STATUSINFO_FAILURE_FLAG);
			return mapMessage.toMap();
		}
		
		//然后审核主表
		rtn = saleOrderService.open(rowID);
		if (rtn != 0){
			mapMessage.setStatusCode(MapMessage.STATUSINFO_FAILURE_CODE);
			mapMessage.setStatusMsg(MapMessage.STATUSINFO_FAILURE_MSG);
			mapMessage.setStatusInfo(MapMessage.STATUSINFO_FAILURE_INFO);
			mapMessage.setStatusFlag(MapMessage.STATUSINFO_FAILURE_FLAG);
			return mapMessage.toMap();
		}
		
		return mapMessage.toMap();
	}

	

	
/*
	public static int saleForecastProcessBeforeFinish() {
		String rowID = ProcessUtils.getProcessData1();
		//System.out.println("请购单ID-->"+rowID);
		Date confirmDate = com.justep.system.util.CommonUtils.getCurrentDate();
		//审核单据
		Map<String ,Object> resultMap = new HashMap<String, Object>();
		resultMap = saleForecastAgreeIt(rowID,confirmDate);
		SaleForecastMessage resultMessage = new SaleForecastMessage();
		resultMessage.fromMap(resultMap);
		if (resultMessage.getStatusFlag().equals(SaleForecastMessage.STATUSINFO_FAILURE_FLAG)){
			return -1;
		}
		return 0;
	}

	public static int saleOrderProcessBeforeFinish() {
		String rowID = ProcessUtils.getProcessData1();
		//System.out.println("请购单ID-->"+rowID);
		Date confirmDate = com.justep.system.util.CommonUtils.getCurrentDate();
		//审核单据
		Map<String ,Object> resultMap = new HashMap<String, Object>();
		resultMap = saleOrderAgreeIt(rowID,confirmDate);
		SaleOrderMessage resultMessage = new SaleOrderMessage();
		resultMessage.fromMap(resultMap);
		if (resultMessage.getStatusFlag().equals(SaleOrderMessage.STATUSINFO_FAILURE_FLAG)){
			return -1;
		}
		return 0;
	}
*/
	
	@Override
	public void saleOrderPrintPDF(String fID ,Document doc) throws DocumentException, IOException {
		
//	@Test
//	public void saleOrderPrintPDF() throws Exception {
//		System.out.println("fID-->"+id);
		
//	    Document doc = new Document();// 创建一个PDF文档，我们的PDF内容都写在上面
	    
//	    PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(new File("c://pdftest//saleOrder.pdf"))); // 将pdf文档写入文件

//		String fID = "bf61ec2bc8163a3ad3d8572ad2fee7c6";
		SaleOrder saleOrder = saleOrderService.getByID(fID);
	    
//	    doc.open();
	    
	    Font fontEN = new Font(BaseFont.createFont(),9);
	    BaseFont baseFont = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);  	    
//	    Font font = new Font(baseFont, 10, Font.ITALIC);
	    Font fontCN = new Font(baseFont, 9);
	    Paragraph pEnterpriseName = new Paragraph(saleOrder.getEnterpriseName(),fontCN);
	    // 居中显示
	    pEnterpriseName.setAlignment(Element.ALIGN_CENTER);
	    pEnterpriseName.setSpacingAfter(-10);
	    Paragraph pBillTypeName = new Paragraph(saleOrder.getBillTypeName(),new Font(baseFont,20));
	    // 居中显示
	    pBillTypeName.setAlignment(Element.ALIGN_CENTER);
	    LineSeparator line = new LineSeparator(1f, 100, BaseColor.BLACK, Element.ALIGN_CENTER, -5f);

	    
	    
	    
	    
	    
	    doc.add(pEnterpriseName);
	    doc.add(pBillTypeName);
	    doc.add(line);
	    
	    
        PdfPTable masterHead = new PdfPTable(8);
        
//        masterHead.setTotalWidth(new float[]{60, 200, 60, 200});
        masterHead.setTotalWidth(new float[]{45, 85, 45, 85, 45, 85, 45, 85});
        masterHead.setLockedWidth(true);
        masterHead.setSpacingBefore(10);
        
        PdfPCell ordrDateCell = new PdfPCell(new Phrase("单据日期:", fontCN));
        ordrDateCell.setUseBorderPadding(true);
        //
        // Setting cell's border width and color
        //
        ordrDateCell.setBorderWidth(0f);
//        ordrDateCell.setBorderColor(BaseColor.BLUE);
        masterHead.addCell(ordrDateCell);

        PdfPCell ordrDateValue = new PdfPCell(new Phrase(saleOrder.getOrderDate().toString(), fontEN));
        ordrDateValue.setUseBorderPadding(true);
        ordrDateValue.setBorderWidth(0f);
        //
        // Setting cell's background color
        //
//        cell2.setBackgroundColor(BaseColor.GRAY);
        //
        // Setting cell's individual border color
        //
//        cell2.setBorderWidthTop(1f);
//        cell2.setBorderColorTop(BaseColor.RED);
//        cell2.setBorderColorRight(BaseColor.GREEN);
//        cell2.setBorderColorBottom(BaseColor.BLUE);
//        cell2.setBorderColorLeft(BaseColor.BLACK);
        masterHead.addCell(ordrDateValue);

        PdfPCell auditCell = new PdfPCell(new Phrase("单据状态:", fontCN));
        auditCell.setUseBorderPadding(true);
        auditCell.setBorderWidth(0f);
        //
        // Setting cell's individual border width
        //
//        cell3.setBorderWidthTop(2f);
//        cell3.setBorderWidthRight(1f);
//        cell3.setBorderWidthBottom(2f);
//        cell3.setBorderWidthLeft(1f);
        masterHead.addCell(auditCell);

        String auditStatus = "待审核";
        String audit = saleOrder.getAudit();
        String state = saleOrder.getState();
        if(audit.equals("confirm")){
        	auditStatus = "已审核";
        }else if(audit.equals("active") && state.equals("confirm")){
        	auditStatus = "审核中";
        }else{
        	auditStatus = "待审核";
        }
        
       PdfPCell auditValue = new PdfPCell(new Phrase(auditStatus, fontCN));
       auditValue.setUseBorderPadding(true);
       auditValue.setBorderWidth(0f);
        //
        // Setting cell's individual border width
        //
//        cell4.setBorderWidthTop(2f);
//        cell4.setBorderWidthRight(1f);
//        cell4.setBorderWidthBottom(2f);
//        cell4.setBorderWidthLeft(1f);
        masterHead.addCell(auditValue);
        
        PdfPCell customerNoCell = new PdfPCell(new Phrase("客户编码:", fontCN));
        customerNoCell.setBorder(0);
        masterHead.addCell(customerNoCell);
        PdfPCell customerNoValue = new PdfPCell(new Phrase(saleOrder.getCustomerNo(), fontEN));
        customerNoValue.setBorder(0);
        masterHead.addCell(customerNoValue);
        
        PdfPCell shortNameCell = new PdfPCell(new Phrase("客户简称:", fontCN));
        shortNameCell.setBorder(0);
        masterHead.addCell(shortNameCell);
        PdfPCell shortNameValue = new PdfPCell(new Phrase(saleOrder.getShortName(), fontCN));
        shortNameValue.setBorder(0);
        masterHead.addCell(shortNameValue);

        //第一行结束
        masterHead.completeRow();
        
        PdfPCell orderNoCell = new PdfPCell(new PdfPCell(new Phrase("单号:", fontCN)));
        orderNoCell.setBorder(0);
        masterHead.addCell(orderNoCell);
        PdfPCell orderNoValue = new PdfPCell(new PdfPCell(new Phrase(saleOrder.getOrderNo(), fontEN)));
        orderNoValue.setBorder(0);
        masterHead.addCell(orderNoValue);
        
        PdfPCell depositRateCell = new PdfPCell(new PdfPCell(new Phrase("定金比率:", fontCN)));
        depositRateCell.setBorder(0);
        masterHead.addCell(depositRateCell);
        String depositRate = saleOrder.getDepositRate().multiply(new BigDecimal(100)).toString() + "%";
        PdfPCell depositRateValue = new PdfPCell(new PdfPCell(new Phrase(depositRate, fontEN)));
        depositRateValue.setBorder(0);
        masterHead.addCell(depositRateValue);
        
        PdfPCell customerNameCell = new PdfPCell(new Phrase("客户名称:", fontCN));
        customerNameCell.setBorder(0);
        masterHead.addCell(customerNameCell);
        PdfPCell customerNameValue = new PdfPCell(new Phrase(saleOrder.getCustomerName(), fontCN));
        customerNameValue.setBorder(0);
        customerNameValue.setColspan(3);
        masterHead.addCell(customerNameValue);
        //第二行结束
        masterHead.completeRow();
        
        PdfPCell factoryNoCell = new PdfPCell(new PdfPCell(new Phrase("工厂编码:", fontCN)));
        factoryNoCell.setBorder(0);
        masterHead.addCell(factoryNoCell);
        PdfPCell factoryNoValue = new PdfPCell(new PdfPCell(new Phrase(saleOrder.getFactoryNo(), fontEN)));
        factoryNoValue.setBorder(0);
        masterHead.addCell(factoryNoValue);
        
        PdfPCell factoryNameCell = new PdfPCell(new PdfPCell(new Phrase("工厂名称:", fontCN)));
        factoryNameCell.setBorder(0);
        masterHead.addCell(factoryNameCell);
        PdfPCell factoryNameValue = new PdfPCell(new PdfPCell(new Phrase(saleOrder.getFactoryName(), fontCN)));
        factoryNameValue.setBorder(0);
        masterHead.addCell(factoryNameValue);
        
        PdfPCell invoiceCategoryLabelCell = new PdfPCell(new PdfPCell(new Phrase("发票类型:", fontCN)));
        invoiceCategoryLabelCell.setBorder(0);
        masterHead.addCell(invoiceCategoryLabelCell);
        PdfPCell invoiceCategoryLabelValue = new PdfPCell(new PdfPCell(new Phrase(saleOrder.getInvoiceCategoryLabel(), fontCN)));
        invoiceCategoryLabelValue.setBorder(0);
        masterHead.addCell(invoiceCategoryLabelValue);
        
        PdfPCell settleCategoryLabelCell = new PdfPCell(new Phrase("结算方式:", fontCN));
        settleCategoryLabelCell.setBorder(0);
        masterHead.addCell(settleCategoryLabelCell);
        PdfPCell settleCategoryLabelValue = new PdfPCell(new Phrase(saleOrder.getSettleCategoryLabel(), fontCN));
        settleCategoryLabelValue.setBorder(0);
        masterHead.addCell(settleCategoryLabelValue);
        //第三行结束
        masterHead.completeRow();
        
        PdfPCell taxTypeLabelCell = new PdfPCell(new PdfPCell(new Phrase("税种:", fontCN)));
        taxTypeLabelCell.setBorder(0);
        masterHead.addCell(taxTypeLabelCell);
        PdfPCell taxTypeLabelValue = new PdfPCell(new PdfPCell(new Phrase(saleOrder.getTaxTypeLabel(), fontCN)));
        taxTypeLabelValue.setBorder(0);
        masterHead.addCell(taxTypeLabelValue);
        
        PdfPCell taxRateCell = new PdfPCell(new PdfPCell(new Phrase("税率:", fontCN)));
        taxRateCell.setBorder(0);
        masterHead.addCell(taxRateCell);
        PdfPCell taxRateValue = new PdfPCell(new PdfPCell(new Phrase(saleOrder.getTaxRate().toString(), fontEN)));
        taxRateValue.setBorder(0);
        masterHead.addCell(taxRateValue);
        
        PdfPCell fAddressCell = new PdfPCell(new Phrase("收货地址:", fontCN));
        fAddressCell.setBorder(0);
        masterHead.addCell(fAddressCell);
        PdfPCell fAddressValue = new PdfPCell(new Phrase(saleOrder.getfAddress(), fontCN));
        fAddressValue.setBorder(0);
        fAddressValue.setColspan(3);
        masterHead.addCell(fAddressValue);
        //第四行结束
        masterHead.completeRow();
        
        PdfPCell employeeNameCell = new PdfPCell(new Phrase("经办人:", fontCN));
        employeeNameCell.setBorder(0);
        masterHead.addCell(employeeNameCell);
        PdfPCell employeeNameValue = new PdfPCell(new Phrase(saleOrder.getEmployeeName(), fontCN));
        employeeNameValue.setBorder(0);
        employeeNameValue.setColspan(3);
        masterHead.addCell(employeeNameValue);
        
        PdfPCell fAddressDetailCell = new PdfPCell(new Phrase("详细地址:", fontCN));
        fAddressDetailCell.setBorder(0);
        masterHead.addCell(fAddressDetailCell);
        PdfPCell fAddressDetailValue = new PdfPCell(new Phrase(saleOrder.getfAddressDetail(), fontCN));
        fAddressDetailValue.setBorder(0);
        fAddressDetailValue.setColspan(3);
        masterHead.addCell(fAddressDetailValue);
        //第五行结束
        masterHead.completeRow();
        
        PdfPCell shipperNameCell = new PdfPCell(new PdfPCell(new Phrase("物流公司:", fontCN)));
        shipperNameCell.setBorder(0);
        masterHead.addCell(shipperNameCell);
        PdfPCell shipperNameValue = new PdfPCell(new PdfPCell(new Phrase(saleOrder.getContacts(), fontCN)));
        shipperNameValue.setBorder(0);
        masterHead.addCell(shipperNameValue);
        
        PdfPCell waybillNoCell = new PdfPCell(new PdfPCell(new Phrase("运单号:", fontCN)));
        waybillNoCell.setBorder(0);
        masterHead.addCell(waybillNoCell);
        PdfPCell waybillNoValue = new PdfPCell(new PdfPCell(new Phrase(saleOrder.getContacts(), fontEN)));
        waybillNoValue.setBorder(0);
        masterHead.addCell(waybillNoValue);
        
        PdfPCell contactsCell = new PdfPCell(new Phrase("联系人:", fontCN));
        contactsCell.setBorder(0);
        masterHead.addCell(contactsCell);
        PdfPCell contactsValue = new PdfPCell(new Phrase(saleOrder.getContacts(), fontCN));
        contactsValue.setBorder(0);
        masterHead.addCell(contactsValue);
        
        PdfPCell mobilePhoneCell = new PdfPCell(new Phrase("联系电话:", fontCN));
        mobilePhoneCell.setBorder(0);
        masterHead.addCell(mobilePhoneCell);
        PdfPCell mobilePhoneValue = new PdfPCell(new Phrase(saleOrder.getMobilePhone(), fontEN));
        mobilePhoneValue.setBorder(0);
        masterHead.addCell(mobilePhoneValue);
        //第六行结束
        masterHead.completeRow();
        
        PdfPCell paymentTermLabelCell = new PdfPCell(new Phrase("付款条件:", fontCN));
        paymentTermLabelCell.setBorder(0);
        masterHead.addCell(paymentTermLabelCell);
        PdfPCell paymentTermLabelValue = new PdfPCell(new Phrase(saleOrder.getPaymentTermLabel(), fontCN));
        paymentTermLabelValue.setBorder(0);
        paymentTermLabelValue.setColspan(7);
        masterHead.addCell(paymentTermLabelValue);
        //第七行结束
        masterHead.completeRow();
        
        PdfPCell commentsCell = new PdfPCell(new Phrase("备注:", fontCN));
        commentsCell.setBorder(0);
        masterHead.addCell(commentsCell);
        PdfPCell commentsValue = new PdfPCell(new Phrase(saleOrder.getComments(), fontCN));
        commentsValue.setBorder(0);
        commentsValue.setColspan(7);
        masterHead.addCell(commentsValue);
        
        //第n行结束
        masterHead.completeRow();

        doc.add(masterHead);
//	    doc.add(line);
	    

        /*
        Image image = Image.getInstance("c://pdftest//smp.png");

        image.setAlignment(Image.ALIGN_RIGHT);
        // 设置边框
        image.setBorder(Image.BOX);
        image.setBorderWidth(2);
        image.setBorderColor(BaseColor.RED);
        // 设置图片大小
        
//        ScaleToFit有两个参数，指的是长和宽的最大值，但是图片的长宽比还是不会变的
//        ScaleAbsoluteHeight设置图片的高度，不管长宽比 ScaleAbsoluteWidth设置图片的宽度，不管长宽比
//        ScalePercent等比例缩放
        
//         image.scaleToFit(100, 100);
//         image.scaleAbsoluteHeight(100f);
//         image.scaleAbsoluteWidth(100f);

        image.scalePercent(50f);
        // 图片旋转30度
        image.setRotationDegrees(30);

        doc.add(image);
        */
        
        
        
        
        
	    //////////////////////////////////////////////////////////////////////////////////////////
	    
        PdfPTable details = new PdfPTable(8);
        details.setTotalWidth(new float[]{15, 70, 70, 80, 65, 75, 65, 80});//520
        details.setLockedWidth(true);
        details.setSpacingBefore(10);

        PdfPCell sharpCell = new PdfPCell(new Phrase("序号", fontCN));
//        sharpCell.setBorder(0);
        sharpCell.setRowspan(4);
        sharpCell.setHorizontalAlignment(Element.ALIGN_CENTER);
        sharpCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        details.addCell(sharpCell);

        PdfPCell itemNoCell = new PdfPCell(new Phrase("物料编码", fontCN));
//        itemNoCell.setBorder(0);
//        itemNoCell.setBorderWidthTop(0);
        itemNoCell.setBorderWidthLeft(0);
        itemNoCell.setBorderWidthBottom(0);
        itemNoCell.setBorderWidthRight(0);
        itemNoCell.setColspan(2);
        details.addCell(itemNoCell);

        PdfPCell projectNoCell = new PdfPCell(new Phrase("项目号", fontCN));
//        projectNoCell.setBorder(0);
        projectNoCell.setBorderWidthLeft(0);
        projectNoCell.setBorderWidthBottom(0);
        projectNoCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        details.addCell(projectNoCell);

        PdfPCell requirementDateCell = new PdfPCell(new Phrase("预交日期", fontCN));
//        requirementDateCell.setBorder(0);
        requirementDateCell.setBorderWidthLeft(0);
        requirementDateCell.setBorderWidthBottom(0);
        requirementDateCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        details.addCell(requirementDateCell);

        PdfPCell itemAmountsCell = new PdfPCell(new Phrase("订货数量", fontCN));
//        itemAmountsCell.setBorder(0);
        itemAmountsCell.setBorderWidthLeft(0);
        itemAmountsCell.setBorderWidthBottom(0);
        itemAmountsCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        details.addCell(itemAmountsCell);

        PdfPCell taxRatesCell = new PdfPCell(new Phrase("税率", fontCN));
//        taxRatesCell.setBorder(0);
        taxRatesCell.setBorderWidthLeft(0);
        taxRatesCell.setBorderWidthBottom(0);
        taxRatesCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        details.addCell(taxRatesCell);

        PdfPCell commentssCell = new PdfPCell(new Phrase("备注", fontCN));
//        commentssCell.setBorder(0);
        commentssCell.setBorderWidthLeft(0);
        commentssCell.setRowspan(4);
        details.addCell(commentssCell);
        
        details.completeRow();
        //第一行结束

        PdfPCell itemDescribeCell = new PdfPCell(new Phrase("名称", fontCN));
//        itemDescribeCell.setBorder(0);
        itemDescribeCell.setBorderWidthTop(0);
        itemDescribeCell.setBorderWidthLeft(0);
        itemDescribeCell.setBorderWidthBottom(0);
        itemDescribeCell.setColspan(3);
        details.addCell(itemDescribeCell);

        PdfPCell taxTypeLabelsCell = new PdfPCell(new Phrase("税种", fontCN));
//        taxTypeLabelsCell.setBorder(0);
        taxTypeLabelsCell.setBorderWidthTop(0);
        taxTypeLabelsCell.setBorderWidthLeft(0);
        taxTypeLabelsCell.setBorderWidthBottom(0);
        taxTypeLabelsCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        details.addCell(taxTypeLabelsCell);

        PdfPCell pickItemAmountsCell = new PdfPCell(new Phrase("已交数量", fontCN));
//        pickItemAmountsCell.setBorder(0);
        pickItemAmountsCell.setBorderWidthTop(0);
        pickItemAmountsCell.setBorderWidthLeft(0);
        pickItemAmountsCell.setBorderWidthBottom(0);
        pickItemAmountsCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        details.addCell(pickItemAmountsCell);

        PdfPCell orderAmountOldsCell = new PdfPCell(new Phrase("未税金额", fontCN));
//        orderAmountOldsCell.setBorder(0);
        orderAmountOldsCell.setBorderWidthTop(0);
        orderAmountOldsCell.setBorderWidthLeft(0);
        orderAmountOldsCell.setBorderWidthBottom(0);
        orderAmountOldsCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        details.addCell(orderAmountOldsCell);

        details.completeRow();
        //第二行结束

        PdfPCell itemPropertyCell = new PdfPCell(new Phrase("规格", fontCN));
//        itemPropertyCell.setBorder(0);
        itemPropertyCell.setBorderWidthTop(0);
        itemPropertyCell.setBorderWidthLeft(0);
        itemPropertyCell.setBorderWidthBottom(0);
        itemPropertyCell.setBorderWidthRight(0);
        itemPropertyCell.setColspan(2);
        details.addCell(itemPropertyCell);

        PdfPCell unitNameCell = new PdfPCell(new Phrase("单位", fontCN));
//        unitNameCell.setBorder(0);
        unitNameCell.setBorderWidthTop(0);
        unitNameCell.setBorderWidthLeft(0);
        unitNameCell.setBorderWidthBottom(0);
        unitNameCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        details.addCell(unitNameCell);

        PdfPCell discountRateCell = new PdfPCell(new Phrase("折扣率", fontCN));
//        discountRateCell.setBorder(0);
        discountRateCell.setBorderWidthTop(0);
        discountRateCell.setBorderWidthLeft(0);
        discountRateCell.setBorderWidthBottom(0);
        discountRateCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        details.addCell(discountRateCell);

        PdfPCell itemPriceCell = new PdfPCell(new Phrase("单价", fontCN));
//        itemPriceCell.setBorder(0);
        itemPriceCell.setBorderWidthTop(0);
        itemPriceCell.setBorderWidthLeft(0);
        itemPriceCell.setBorderWidthBottom(0);
        itemPriceCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        details.addCell(itemPriceCell);

        PdfPCell orderAmountTaxsCell = new PdfPCell(new Phrase("税额", fontCN));
//        orderAmountTaxsCell.setBorder(0);
        orderAmountTaxsCell.setBorderWidthTop(0);
        orderAmountTaxsCell.setBorderWidthLeft(0);
        orderAmountTaxsCell.setBorderWidthBottom(0);
        orderAmountTaxsCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        details.addCell(orderAmountTaxsCell);

        details.completeRow();
        //第三行结束

        PdfPCell floorNoCell = new PdfPCell(new Phrase("库存地", fontCN));
//        floorNoCell.setBorder(0);
        floorNoCell.setBorderWidthTop(0);
        floorNoCell.setBorderWidthLeft(0);
        floorNoCell.setBorderWidthRight(0);
        floorNoCell.setColspan(2);
        details.addCell(floorNoCell);

        PdfPCell storageNoCell = new PdfPCell(new Phrase("仓库编码", fontCN));
//        storageNoCell.setBorder(0);
        storageNoCell.setBorderWidthTop(0);
        storageNoCell.setBorderWidthLeft(0);
        storageNoCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        details.addCell(storageNoCell);

        PdfPCell emptyCell = new PdfPCell(new Phrase("", fontCN));
//        emptyCell.setBorder(0);
        emptyCell.setBorderWidthTop(0);
        emptyCell.setBorderWidthLeft(0);
        emptyCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        details.addCell(emptyCell);

        PdfPCell orderAmountCell = new PdfPCell(new Phrase("金额", fontCN));
//        orderAmountCell.setBorder(0);
        orderAmountCell.setBorderWidthTop(0);
        orderAmountCell.setBorderWidthLeft(0);
        orderAmountCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        details.addCell(orderAmountCell);

        PdfPCell orderAmountTotalsCell = new PdfPCell(new Phrase("价税合计", fontCN));
//        orderAmountTotalsCell.setBorder(0);
        orderAmountTotalsCell.setBorderWidthTop(0);
        orderAmountTotalsCell.setBorderWidthLeft(0);
        orderAmountTotalsCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        details.addCell(orderAmountTotalsCell);

        details.completeRow();
        //第四行结束
        
        
//        doc.add(details);
        
        ////////////////////////////////////////////////////////////////////////////////////////////
        
        
	    //////////////////////////////////////////////////////////////////////////////////////////
        List<SaleOrderDetail> saleOrderDetails = saleOrderDetailService.getByMasterID(fID);
        if(saleOrderDetails.size()>0){
    	    
//            PdfPTable detailsValue = new PdfPTable(8);
//            
//            detailsValue.setTotalWidth(new float[]{20, 70, 70, 80, 80, 80, 60, 60});//520
//            detailsValue.setLockedWidth(true);
//            detailsValue.setSpacingBefore(10);
            
            for(int i=0;i<saleOrderDetails.size();i++){
            	SaleOrderDetail saleOrderDetail = saleOrderDetails.get(i);

            	//序号
            	String rowNo = String.valueOf(i+1);
                PdfPCell sharpValue = new PdfPCell(new Phrase(rowNo, fontEN));
//                sharpValue.setBorder(0);
                sharpValue.setBorderWidthTop(0);
                sharpValue.setRowspan(4);
                sharpValue.setHorizontalAlignment(Element.ALIGN_CENTER);
                sharpValue.setVerticalAlignment(Element.ALIGN_MIDDLE);
                details.addCell(sharpValue);

                PdfPCell itemNoValue = new PdfPCell(new Phrase(saleOrderDetail.getItemNo(), fontEN));
//                itemNoValue.setBorder(0);
                itemNoValue.setBorderWidthTop(0);
                itemNoValue.setBorderWidthLeft(0);
                itemNoValue.setBorderWidthBottom(0);
                itemNoValue.setBorderWidthRight(0);
                itemNoValue.setColspan(2);
                details.addCell(itemNoValue);

                PdfPCell projectNoValue = new PdfPCell(new Phrase(saleOrderDetail.getProjectNo(), fontEN));
//                projectNoValue.setBorder(0);
                projectNoValue.setBorderWidthTop(0);
                projectNoValue.setBorderWidthLeft(0);
                projectNoValue.setBorderWidthBottom(0);
                projectNoValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
                details.addCell(projectNoValue);

                PdfPCell requirementDateValue = new PdfPCell(new Phrase(saleOrderDetail.getRequirementDate()==null?"":saleOrderDetail.getRequirementDate().toString(), fontEN));
//                requirementDateValue.setBorder(0);
                requirementDateValue.setBorderWidthTop(0);
                requirementDateValue.setBorderWidthLeft(0);
                requirementDateValue.setBorderWidthBottom(0);
                requirementDateValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
                details.addCell(requirementDateValue);

                PdfPCell itemAmountValue = new PdfPCell(new Phrase(saleOrderDetail.getItemAmount().toString(), fontEN));
//                itemAmountValue.setBorder(0);
                itemAmountValue.setBorderWidthTop(0);
                itemAmountValue.setBorderWidthLeft(0);
                itemAmountValue.setBorderWidthBottom(0);
                itemAmountValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
                details.addCell(itemAmountValue);

                PdfPCell taxRatesValue = new PdfPCell(new Phrase(saleOrderDetail.getTaxRate().toString(), fontEN));
//                taxRatesValue.setBorder(0);
                taxRatesValue.setBorderWidthTop(0);
                taxRatesValue.setBorderWidthLeft(0);
                taxRatesValue.setBorderWidthBottom(0);
                taxRatesValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
                details.addCell(taxRatesValue);

                PdfPCell commentssValue = new PdfPCell(new Phrase(saleOrderDetail.getComments(), fontCN));
//                commentssValue.setBorder(0);
                commentssValue.setBorderWidthTop(0);
                commentssValue.setBorderWidthLeft(0);
                commentssValue.setRowspan(4);
                details.addCell(commentssValue);
                
                details.completeRow();
                //第一行结束
 
                PdfPCell itemDescribeValue = new PdfPCell(new Phrase(saleOrderDetail.getItemName(), fontCN));
//              itemDescribeValue.setBorder(0);
                itemDescribeValue.setBorderWidthTop(0);
                itemDescribeValue.setBorderWidthLeft(0);
                itemDescribeValue.setBorderWidthBottom(0);
                itemDescribeValue.setColspan(3);
              details.addCell(itemDescribeValue);

              PdfPCell taxTypeLabelsValue = new PdfPCell(new Phrase(saleOrderDetail.getTaxTypeLabel(), fontCN));
//              taxTypeLabelsValue.setBorder(0);
              taxTypeLabelsValue.setBorderWidthTop(0);
              taxTypeLabelsValue.setBorderWidthLeft(0);
              taxTypeLabelsValue.setBorderWidthBottom(0);
              taxTypeLabelsValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
              details.addCell(taxTypeLabelsValue);


              PdfPCell pickItemAmountValue = new PdfPCell(new Phrase(saleOrderDetail.getPickItemAmount().toString(), fontEN));
//              pickItemAmountValue.setBorder(0);
              pickItemAmountValue.setBorderWidthTop(0);
              pickItemAmountValue.setBorderWidthLeft(0);
              pickItemAmountValue.setBorderWidthBottom(0);
              pickItemAmountValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
              details.addCell(pickItemAmountValue);

              PdfPCell orderAmountOldsValue = new PdfPCell(new Phrase(saleOrderDetail.getOrderAmountOld().toString(), fontEN));
//              orderAmountOldsValue.setBorder(0);
              orderAmountOldsValue.setBorderWidthTop(0);
              orderAmountOldsValue.setBorderWidthLeft(0);
              orderAmountOldsValue.setBorderWidthBottom(0);
              orderAmountOldsValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
              details.addCell(orderAmountOldsValue);

              details.completeRow();
              //第二行结束

              PdfPCell itemPropertyValue = new PdfPCell(new Phrase(saleOrderDetail.getItemProperty(), fontCN));
//              itemPropertyValue.setBorder(0);
              itemPropertyValue.setBorderWidthTop(0);
              itemPropertyValue.setBorderWidthLeft(0);
              itemPropertyValue.setBorderWidthBottom(0);
              itemPropertyValue.setBorderWidthRight(0);
              itemPropertyValue.setColspan(2);
              details.addCell(itemPropertyValue);

              PdfPCell unitNameValue = new PdfPCell(new Phrase(saleOrderDetail.getUnitName(), fontCN));
//              unitNameValue.setBorder(0);
              unitNameValue.setBorderWidthTop(0);
              unitNameValue.setBorderWidthLeft(0);
              unitNameValue.setBorderWidthBottom(0);
              unitNameValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
              details.addCell(unitNameValue);

              String discountRates = saleOrderDetail.getDiscountRate().multiply(new BigDecimal(100)).toString() + "%";
              PdfPCell discountRateValue = new PdfPCell(new Phrase(discountRates, fontEN));
//              discountRateValue.setBorder(0);
              discountRateValue.setBorderWidthTop(0);
              discountRateValue.setBorderWidthLeft(0);
              discountRateValue.setBorderWidthBottom(0);
              discountRateValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
              details.addCell(discountRateValue);

              PdfPCell itemPriceValue = new PdfPCell(new Phrase(saleOrderDetail.getItemPrice().toString(), fontEN));
//              itemPriceValue.setBorder(0);
              itemPriceValue.setBorderWidthTop(0);
              itemPriceValue.setBorderWidthLeft(0);
              itemPriceValue.setBorderWidthBottom(0);
              itemPriceValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
              details.addCell(itemPriceValue);

              PdfPCell orderAmountTaxValue = new PdfPCell(new Phrase(saleOrderDetail.getOrderAmountTax().toString(), fontEN));
//              orderAmountTaxValue.setBorder(0);
              orderAmountTaxValue.setBorderWidthTop(0);
              orderAmountTaxValue.setBorderWidthLeft(0);
              orderAmountTaxValue.setBorderWidthBottom(0);
              orderAmountTaxValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
              details.addCell(orderAmountTaxValue);

              details.completeRow();
              //第三行结束
              

              PdfPCell floorNoValue = new PdfPCell(new Phrase(saleOrderDetail.getFloorNo(), fontCN));
//              floorNoValue.setBorder(0);
              floorNoValue.setBorderWidthTop(0);
              floorNoValue.setBorderWidthLeft(0);
              floorNoValue.setBorderWidthRight(0);
              floorNoValue.setColspan(2);
              details.addCell(floorNoValue);

              PdfPCell storageNoValue = new PdfPCell(new Phrase(saleOrderDetail.getStorageNo(), fontEN));
//              storageNoValue.setBorder(0);
              storageNoValue.setBorderWidthTop(0);
              storageNoValue.setBorderWidthLeft(0);
              storageNoValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
              details.addCell(storageNoValue);

              PdfPCell emptyValue = new PdfPCell(new Phrase("", fontCN));
//              emptyValue.setBorder(0);
              emptyValue.setBorderWidthTop(0);
              emptyValue.setBorderWidthLeft(0);
              emptyValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
              details.addCell(emptyValue);

              PdfPCell orderAmountValue = new PdfPCell(new Phrase(saleOrderDetail.getOrderAmount().toString(), fontEN));
//              orderAmountValue.setBorder(0);
              orderAmountValue.setBorderWidthTop(0);
              orderAmountValue.setBorderWidthLeft(0);
              orderAmountValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
              details.addCell(orderAmountValue);

              PdfPCell orderAmountTotalValue = new PdfPCell(new Phrase(saleOrderDetail.getOrderAmountTotal().toString(), fontEN));
//              orderAmountTotalValue.setBorder(0);
              orderAmountTotalValue.setBorderWidthTop(0);
              orderAmountTotalValue.setBorderWidthLeft(0);
              orderAmountTotalValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
              details.addCell(orderAmountTotalValue);

              details.completeRow();
              //第四行结束
              
            }
            
            doc.add(details);
      	
        }
        ////////////////////////////////////////////////////////////////////////////////////////////
        
//	    doc.add(line);

	    
        PdfPTable masterFoot = new PdfPTable(8);
        
        masterFoot.setTotalWidth(new float[]{45, 85, 45, 85, 45, 85, 45, 85});
        masterFoot.setLockedWidth(true);
//        masterFoot.setSpacingBefore(10);

        PdfPCell detailsCountCell = new PdfPCell(new Phrase("笔数:", fontCN));
//        detailsCountCell.setBorder(0);
        detailsCountCell.setBorderWidthTop(0);
        detailsCountCell.setBorderWidthBottom(0);
        detailsCountCell.setBorderWidthRight(0);
        masterFoot.addCell(detailsCountCell);

        PdfPCell detailsCountValue = new PdfPCell(new Phrase(String.valueOf(saleOrder.getDetailsCount()), fontEN));
        detailsCountValue.setBorder(0);
        masterFoot.addCell(detailsCountValue);

        PdfPCell r1emptyCell = new PdfPCell(new Phrase(""));
//        r1emptyCell.setBorder(0);
        r1emptyCell.setBorderWidthTop(0);
        r1emptyCell.setBorderWidthBottom(0);
        r1emptyCell.setBorderWidthLeft(0);
        r1emptyCell.setColspan(6);
        masterFoot.addCell(r1emptyCell);

        //第一行结束
        masterFoot.completeRow();

        PdfPCell itemAmountCell = new PdfPCell(new Phrase("数量合计:", fontCN));
//        itemAmountCell.setBorder(0);
        itemAmountCell.setBorderWidthTop(0);
        itemAmountCell.setBorderWidthBottom(0);
        itemAmountCell.setBorderWidthRight(0);
        masterFoot.addCell(itemAmountCell);

        PdfPCell itemAmountValue = new PdfPCell(new Phrase(saleOrder.getItemAmount().toString(), fontEN));
        itemAmountValue.setBorder(0);
        masterFoot.addCell(itemAmountValue);

        PdfPCell orderAmountOldCell = new PdfPCell(new Phrase("未税金额:", fontCN));
        orderAmountOldCell.setBorder(0);
        masterFoot.addCell(orderAmountOldCell);

        PdfPCell orderAmountOldValue = new PdfPCell(new Phrase(saleOrder.getOrderAmountOld().toString(), fontEN));
        orderAmountOldValue.setBorder(0);
        masterFoot.addCell(orderAmountOldValue);

        PdfPCell orderAmountTaxCell = new PdfPCell(new Phrase("税额:", fontCN));
        orderAmountTaxCell.setBorder(0);
        masterFoot.addCell(orderAmountTaxCell);

        PdfPCell orderAmountTaxValue = new PdfPCell(new Phrase(saleOrder.getOrderAmountTax().toString(), fontEN));
        orderAmountTaxValue.setBorder(0);
        masterFoot.addCell(orderAmountTaxValue);

        PdfPCell orderAmountTotalCell = new PdfPCell(new Phrase("价税合计:", fontCN));
        orderAmountTotalCell.setBorder(0);
        masterFoot.addCell(orderAmountTotalCell);

        PdfPCell orderAmountTotalValue = new PdfPCell(new Phrase(saleOrder.getOrderAmountTotal().toString(), fontEN));
//        orderAmountTotalValue.setBorder(0);
        orderAmountTotalValue.setBorderWidthTop(0);
        orderAmountTotalValue.setBorderWidthBottom(0);
        orderAmountTotalValue.setBorderWidthLeft(0);
        masterFoot.addCell(orderAmountTotalValue);

        //第二行结束
        masterFoot.completeRow();

        PdfPCell pickItemAmountCell = new PdfPCell(new Phrase("已交数量:", fontCN));
//        pickItemAmountCell.setBorder(0);
        pickItemAmountCell.setBorderWidthTop(0);
        pickItemAmountCell.setBorderWidthRight(0);
        masterFoot.addCell(pickItemAmountCell);

        PdfPCell pickItemAmountValue = new PdfPCell(new Phrase(saleOrder.getPickItemAmount().toString(), fontEN));
//        pickItemAmountValue.setBorder(0);
        pickItemAmountValue.setBorderWidthTop(0);
        pickItemAmountValue.setBorderWidthLeft(0);
        pickItemAmountValue.setBorderWidthRight(0);
        masterFoot.addCell(pickItemAmountValue);

        PdfPCell r3emptyCell = new PdfPCell(new Phrase(""));
//        r3emptyCell.setBorder(0);
        r3emptyCell.setBorderWidthTop(0);
        r3emptyCell.setBorderWidthLeft(0);
        r3emptyCell.setColspan(6);
        masterFoot.addCell(r3emptyCell);

        //第三行结束
        masterFoot.completeRow();

        doc.add(masterFoot);
        
        
        
	    
        PdfPTable masterTail = new PdfPTable(8);
        
        masterTail.setTotalWidth(new float[]{45, 65, 45, 105, 45, 65, 45, 105});
        masterTail.setLockedWidth(true);
        masterTail.setSpacingBefore(10);

        PdfPCell cUsernameCell = new PdfPCell(new Phrase("制单:", fontCN));
        cUsernameCell.setBorder(0);
        masterTail.addCell(cUsernameCell);

        PdfPCell cUsernameValue = new PdfPCell(new Phrase(saleOrder.getcUsername(), fontCN));
        cUsernameValue.setBorder(0);
        masterTail.addCell(cUsernameValue);

        PdfPCell cDatetimeCell = new PdfPCell(new Phrase("制单时间:", fontCN));
        cDatetimeCell.setBorder(0);
        masterTail.addCell(cDatetimeCell);

        PdfPCell cDatetimeValue = new PdfPCell(new Phrase(saleOrder.getcDatetime().toString(), fontEN));
        cDatetimeValue.setBorder(0);
        masterTail.addCell(cDatetimeValue);

        PdfPCell tUsernameCell = new PdfPCell(new Phrase("审核:", fontCN));
        tUsernameCell.setBorder(0);
        masterTail.addCell(tUsernameCell);

        PdfPCell tUsernameValue = new PdfPCell(new Phrase(saleOrder.gettUsername(), fontCN));
        tUsernameValue.setBorder(0);
        masterTail.addCell(tUsernameValue);

        PdfPCell tDatetimeCell = new PdfPCell(new Phrase("审核时间:", fontCN));
        tDatetimeCell.setBorder(0);
        masterTail.addCell(tDatetimeCell);

        PdfPCell tDatetimeValue = new PdfPCell(new Phrase(saleOrder.gettDatetime()==null?"":saleOrder.gettDatetime().toString(), fontEN));
        tDatetimeValue.setBorder(0);
        masterTail.addCell(tDatetimeValue);


        masterTail.completeRow();
        

        doc.add(masterTail);
	    
        Chunk printTimeChunk = new Chunk("打印时间: ",fontCN);
        String printTime = Utils.getCurrentDateTime().toString();
        Paragraph printTimeParagraph = new Paragraph(printTimeChunk);
        Chunk printTimeValueChunk = new Chunk(printTime,fontEN);
        printTimeParagraph.add(printTimeValueChunk);
        printTimeParagraph.setAlignment(Element.ALIGN_RIGHT);
	    doc.add(printTimeParagraph);
	    
        
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	 

	    
//	    doc.close();
	    
	    
	    
//        int pageNumber = doc.getPageNumber();
//        System.out.println(pageNumber);
//	    Rectangle rect = doc.getPageSize();
//	    System.out.println("rect.getHeight()-->"+rect.getHeight());
//	    System.out.println("rect.getWidth()-->"+rect.getWidth());
//	    System.out.println("rect.getLeft()-->"+rect.getLeft());
//	    System.out.println("rect.getTop()-->"+rect.getTop());
//	    System.out.println("rect.getBottom()-->"+rect.getBottom());
//	    System.out.println("rect.getRight()-->"+rect.getRight());
//	    System.out.println("rect.getBorder()-->"+rect.getBorder());
//	    System.out.println("rect.getBorderWidth()-->"+rect.getBorderWidth());
//	    System.out.println("rect.getBorderWidthTop()-->"+rect.getBorderWidthTop());
//	    System.out.println("rect.getBorderWidthLeft()-->"+rect.getBorderWidthLeft());
//	    System.out.println("rect.getBorderWidthBottom()-->"+rect.getBorderWidthBottom());
//	    System.out.println("rect.getBorderWidthRight()-->"+rect.getBorderWidthRight());

	}

	//打印客户订单
	//下面是供餐厅使用的
	@Override
	public JSONObject saleOrderPrintWEB(String fID) {
	    JSONObject json = new JSONObject();
		SaleOrder saleOrder = saleOrderService.getByID(fID);
		JSONObject master = (JSONObject) JSONObject.toJSON(saleOrder);
        
        json.put("master", master);
        
        List<SaleOrderDetail> saleOrderDetails = saleOrderDetailService.getByMasterID(fID);
        if(saleOrderDetails.size()>0){
        	JSONArray slaves = new JSONArray();
        	for(int i=0;i<saleOrderDetails.size();i++){
            	SaleOrderDetail saleOrderDetail = saleOrderDetails.get(i);
        		JSONObject slave = (JSONObject) JSONObject.toJSON(saleOrderDetail);
        		slaves.add(slave);
        	}
        	json.put("slaves", slaves);
        }
        
        json.put("code", 0);
        
        return json;
	}

	
	
	
	@Override
    public void afterInsertOrderDetail(SaleOrderDetail obj){
    	//System.out.println("com.iune.erp.sale.ISaleOrderDetailDao.insert");
    	
		//处理关联单据（销售预测）
//		if (obj.getOrigin()!=null && "XSYC".equals(obj.getOrigin()) && obj.getOriginNo()!=null){
//			//更新请购单的正在订购数量
//			saleForecastDetailService.updatePickItemQuantityIng(obj.getOriginNo(),obj.getEnterpriseNo(),obj.getItemAmount());
//		}
		
    }
    
	@Override
    public void beforeDeleteOrderDetail(String fID){
    	System.out.println("fID-->"+fID);
    	
//		SaleOrderDetail obj = saleOrderDetailService.getByID(fID);
		
		//处理关联单据（销售预测）
//		if (obj.getOrigin()!=null && "XSYC".equals(obj.getOrigin()) && obj.getOriginNo()!=null ){
//			//更新请购单的正在订购数量
//			saleForecastDetailService.updatePickItemQuantityIng(obj.getOriginNo(),obj.getEnterpriseNo(),obj.getItemAmount().negate());
//		}
    }
	
	@Transactional
	@Override
	public StorageRecord storageRecordXSCKInsert(SaleOrder saleOrder
			,int flowType 
			,String cUsercode,String cUsername,String userId
			,String employeeNo,String employeeName){

		StorageRecord storageRecord = null;
		List<StorageRecordDetail> storageRecordDetails = null;
		
		//打包主表
		if(saleOrder==null){
			//源单据不存在
			return null;
		}
		
		String enterpriseNo = saleOrder.getEnterpriseNo();//SecurityService.getCurrentOgn().getsFID();
		String enterpriseName = saleOrder.getEnterpriseName();//SecurityService.getCurrentOgn().getsName();
		
		String billType = "XSCK";//销售发货单
		
		Map<String,Object> map = settingService.getBillParam(billType, enterpriseNo);
		String billTypeName = (String) map.get("billTypeName");
		String systemCode = (String) map.get("systemCode");
//		int flowType = (int) map.get("flowType");
		String revOpay = (String) map.get("revOpay");
		int direction = (int) map.get("direction");
		int dealType = (int) map.get("dealType");
		String costingCode = (String) map.get("costingCode");
		String autoCode = (String) map.get("autoCode");
		String origin = (String) map.get("origin");
		String originName = (String) map.get("originName");
		String billNo = (String) map.get("billNo");
		
//		storageRecord = storageRecordService.packing(newBillType, cUsercode, cUsername, userId, enterpriseNo, enterpriseName);
		storageRecord = storageRecordService.packing(billType, billTypeName, systemCode, flowType, revOpay, direction, dealType, costingCode, autoCode, origin, originName, billNo, cUsercode, cUsername, userId, enterpriseNo, enterpriseName);
		
		//发货日期
//		if(orderDate!=null && !orderDate.equals("")){
//			storageRecord.setOrderDate(Date.valueOf(orderDate));
//		}
		
		storageRecord.setRetailFlag(saleOrder.getRetailFlag());
		storageRecord.setGuestNumber(saleOrder.getGuestNumber());
		
		storageRecord.setOrderNo(saleOrder.getOrderNo());
		storageRecord.setPackFlag(saleOrder.getPackFlag());
		
		storageRecord.setOrigin(saleOrder.getBillType());
		storageRecord.setOriginName(saleOrder.getBillTypeName());
		storageRecord.setOriginNo(saleOrder.getOrderNo());
		
		storageRecord.setFactoryID(saleOrder.getFactoryID());
		storageRecord.setFactoryNo(saleOrder.getFactoryNo());
		storageRecord.setFactoryName(saleOrder.getFactoryName());
		
		storageRecord.setEmployeeNo(saleOrder.getEmployeeNo());
		storageRecord.setEmployeeName(saleOrder.getEmployeeName());
		
		storageRecord.setStorageTypeD(saleOrder.getStorageTypeD());
		storageRecord.setStorageTypeDLabel(saleOrder.getStorageTypeDLabel());
		storageRecord.setProviderID(saleOrder.getCustomerID());
		storageRecord.setProviderNo(saleOrder.getCustomerNo());
		storageRecord.setShortName(saleOrder.getShortName());
		storageRecord.setProviderName(saleOrder.getCustomerName());
		
		storageRecord.setStorageType(saleOrder.getStorageType());
		storageRecord.setStorageTypeLabel(saleOrder.getStorageTypeLabel());
		storageRecord.setStorageID(saleOrder.getStorageID());
		storageRecord.setStorageNo(saleOrder.getStorageNo());
		storageRecord.setStorageName(saleOrder.getStorageName());
		storageRecord.setFloorNo(saleOrder.getFloorNo());
		
		storageRecord.setTaxType(saleOrder.getTaxType());
		storageRecord.setTaxTypeLabel(saleOrder.getTaxTypeLabel());
		storageRecord.setTaxRate(saleOrder.getTaxRate());
		
		storageRecord.setInvoiceCategory(saleOrder.getInvoiceCategory());
		storageRecord.setInvoiceCategoryLabel(saleOrder.getInvoiceCategoryLabel());
		storageRecord.setSettleCategory(saleOrder.getSettleCategory());
		storageRecord.setSettleCategoryLabel(saleOrder.getSettleCategoryLabel());
		
		storageRecord.setOrderNo(saleOrder.getOrderNo());
		
		storageRecord.setfAddress(saleOrder.getfAddress());
		storageRecord.setfAddressDetail(saleOrder.getfAddressDetail());
		storageRecord.setContacts(saleOrder.getContacts());
		storageRecord.setMobilePhone(saleOrder.getMobilePhone());
		storageRecord.setfPhone(saleOrder.getfPhone());
		
		storageRecord.setItemAmount(saleOrder.getItemAmount());
		storageRecord.setOrderAmount(saleOrder.getOrderAmount());
		storageRecord.setOrderAmountOld(saleOrder.getOrderAmountOld());
		storageRecord.setOrderAmountTax(saleOrder.getOrderAmountTax());
		storageRecord.setOrderAmountTotal(saleOrder.getOrderAmountTotal());
		
		storageRecord.setOrderWeight(saleOrder.getOrderWeight());
		storageRecord.setOrderSize(saleOrder.getOrderSize());
//		storageRecord.setFreightAmount(saleOrder.getFreightAmount());
		
//		storageRecord.setPickFlag(pickFlag);
		
		storageRecord.setDepositRate(saleOrder.getDepositRate());
		storageRecord.setDiscountAmount(saleOrder.getDiscountAmount());
		storageRecord.setDiscountRate(saleOrder.getDiscountRate());
		
//		storageRecord.setShipperID(saleOrder.getShipperID());
//		storageRecord.setShipperName(saleOrder.getShipperName());
//		storageRecord.setWaybillNo(saleOrder.getWaybillNo());
		
//			storageRecord.setResultStatus("待审核");
//			storageRecord.setPaymentStatus("待开票");
		
//		int direction = storageRecord.getDirection();
//		BigDecimal bgDirection = new BigDecimal(direction);
		
		
		//子表
		List<SaleOrderDetail> saleOrderDetails = saleOrderService.getByMasterID(saleOrder.getfID());
		if(saleOrderDetails.size()>0){
			storageRecordDetails = new ArrayList<StorageRecordDetail>();
		}
		for(SaleOrderDetail saleOrderDetail : saleOrderDetails){
			StorageRecordDetail storageRecordDetail = storageRecordDetailService.packing(storageRecord);
			storageRecord.setMaxDetailNo(storageRecord.getMaxDetailNo()+1);
			storageRecord.setDetailsCount(storageRecord.getDetailsCount()+1);
			
			storageRecordDetail.setOrigin(saleOrderDetail.getBillType());
			storageRecordDetail.setOriginName(saleOrderDetail.getBillTypeName());
			storageRecordDetail.setOriginNo(saleOrderDetail.getOrderNo());
			storageRecordDetail.setOriginSerialNo(saleOrderDetail.getSerialNo());
			
			//物料
			storageRecordDetail.setItemID(saleOrderDetail.getItemID());
			storageRecordDetail.setItemNo(saleOrderDetail.getItemNo());
			storageRecordDetail.setItemName(saleOrderDetail.getItemName());
			storageRecordDetail.setItemProperty(saleOrderDetail.getItemProperty());
			storageRecordDetail.setUnitCode(saleOrderDetail.getUnitCode());
			storageRecordDetail.setUnitName(saleOrderDetail.getUnitName());
			
			FileItem fileItem = fileItemService.getByID(storageRecordDetail.getItemID());

//			storageRecordDetail.setProcess(fileItem.getProcess());
//			storageRecordDetail.setProcessLabel(fileItem.getProcessLabel());
			storageRecordDetail.setQualityType(fileItem.getQualityType());
			storageRecordDetail.setQualityTypeLabel(fileItem.getQualityTypeLabel());
			//处理检验状态/////////////////////////////////////////////////////////
			int qualityType = fileItem.getQualityType();
			if(qualityType==0){
				storageRecordDetail.setQualityStatus(0);
				storageRecordDetail.setQualityStatusLabel("0.免检");
			}else{
				storageRecordDetail.setQualityStatus(1);
				storageRecordDetail.setQualityStatusLabel("1:待验");
			}
			////////////////////////////////////////////////////////////////////////
			
			storageRecordDetail.setMaterialType(1);
			storageRecordDetail.setMaterialTypeLabel("1.直接材料");
			
			//单价
			storageRecordDetail.setItemPrice(saleOrderDetail.getItemPrice());
			storageRecordDetail.setDiscountRate(saleOrderDetail.getDiscountRate());

			//数量
			storageRecordDetail.setItemAmount(saleOrderDetail.getItemAmount());
			storageRecordDetail.setArriveAmount(saleOrderDetail.getItemAmount());
			storageRecordDetail.setPriceAmount(saleOrderDetail.getItemAmount());
			//件数
			storageRecordDetail.setPieceQuantity(saleOrderDetail.getPieceQuantity());
			
			///////////////////////////////////////////////////////////////
			storageRecordDetail.setPiecePackage(saleOrderDetail.getPiecePackage());
			storageRecordDetail.setDiscountAmount(saleOrderDetail.getDiscountAmount());
			storageRecordDetail.setTaxType(saleOrderDetail.getTaxType());
			storageRecordDetail.setTaxTypeLabel(saleOrderDetail.getTaxTypeLabel());
			storageRecordDetail.setTaxRate(saleOrderDetail.getTaxRate());
			storageRecordDetail.setSbomID(saleOrderDetail.getSbomID());
			storageRecordDetail.setLv(saleOrderDetail.getLv());
			storageRecordDetail.setSttts(saleOrderDetail.getSttts());
			storageRecordDetail.setCheckin(saleOrderDetail.getCheckin());
			/////////////////////////////////////////////////////////////////
			
			storageRecordDetail.setOrderAmount(saleOrderDetail.getOrderAmount());
			storageRecordDetail.setOrderAmountOld(saleOrderDetail.getOrderAmountOld());
			storageRecordDetail.setOrderAmountTax(saleOrderDetail.getOrderAmountTax());
			storageRecordDetail.setOrderAmountTotal(saleOrderDetail.getOrderAmountTotal());
			
			storageRecordDetail.setStorageType(saleOrderDetail.getStorageType());
			storageRecordDetail.setStorageTypeLabel(saleOrderDetail.getStorageTypeLabel());
			storageRecordDetail.setStorageID(saleOrderDetail.getStorageID());
			storageRecordDetail.setStorageNo(saleOrderDetail.getStorageNo());
			storageRecordDetail.setStorageName(saleOrderDetail.getStorageName());
			storageRecordDetail.setFloorNo(saleOrderDetail.getFloorNo());
			
			//账数量，保留两位小数
//			BigDecimal accountQuantityO = storageRecordDetail.getPriceAmount().multiply(bgDirection);
//			accountQuantityO = accountQuantityO.setScale(2, BigDecimal.ROUND_HALF_UP);
//			storageRecordDetail.setAccountQuantityO(accountQuantityO);
			//件数
//			BigDecimal pieceQuantityO = storageRecordDetail.getPieceQuantity().multiply(bgDirection);
//			pieceQuantityO = pieceQuantityO.setScale(2, BigDecimal.ROUND_HALF_UP);
//			storageRecordDetail.setPieceQuantityO(pieceQuantityO);
			
			//即时成本计算（暂时不做）
			
			storageRecordDetail.setBatchNo(fileItem.getBatchNo());
			storageRecordDetail.setStoreNo(fileItem.getStoreNo());
			
			storageRecordDetail.setOrderNo(saleOrderDetail.getOrderNo());
			
			//运费及其他费用
//			storageRecordDetail.setFreightAmount(saleOrderDetail.getFreightAmount());
//			storageRecordDetail.setApportionAmount(saleOrderDetail.getApportionAmount());
			//重量体积
			storageRecordDetail.setItemWeight(saleOrderDetail.getItemWeight());
			storageRecordDetail.setItemSize(saleOrderDetail.getItemSize());
			storageRecordDetail.setOrderWeight(saleOrderDetail.getOrderWeight());
			storageRecordDetail.setOrderSize(saleOrderDetail.getOrderSize());
		
			//累计主表合计金额
			/*
			storageRecord.setItemAmount(storageRecord.getItemAmount().add(storageRecordDetail.getItemAmount()));
			storageRecord.setOrderAmount(storageRecord.getOrderAmount().add(storageRecordDetail.getOrderAmount()));
			storageRecord.setOrderAmountOld(storageRecord.getOrderAmountOld().add(storageRecordDetail.getOrderAmountOld()));
			storageRecord.setOrderAmountTax(storageRecord.getOrderAmountTax().add(storageRecordDetail.getOrderAmountTax()));
			storageRecord.setOrderAmountTotal(storageRecord.getOrderAmountTotal().add(storageRecordDetail.getOrderAmountTotal()));
			*/
			
			storageRecordDetails.add(storageRecordDetail);
		}
		
		//插入主表
		if(storageRecord!=null){
			storageRecordService.insert(storageRecord);
			//插入子表
			if(storageRecordDetails!=null){
				for(StorageRecordDetail storageRecordDetail : storageRecordDetails){
					storageRecordDetailService.insert(storageRecordDetail);
				}
			}
		}
		return storageRecord;
	}
	
	
	
	//提交（数据验证通过之后执行）
	@Transactional
	private int submitRelation(StorageRecordDetail obj){
		
		//TODO 退库处理
		if ((obj.getBillType().equals("XSRK") && obj.getOrigin().equals("XSCK"))){
			storageRecordDetailService.updateBackItemQuantityIng(
						obj.getOriginNo()
						,obj.getOriginSerialNo()
						,obj.getOrigin()
						,obj.getEnterpriseNo()
						,obj.getItemAmount()
						,obj.getWasterAmount()
						,obj.getUllageAmount()
						,obj.getArriveAmountBack()
						);
		}
		
		//TODO 报废处理
		
		if (obj.getBillType().equals("BFDJ")){
			if (obj.getOrigin().equals("XSRK")){
				
				//更新正在处理废品数量
				storageRecordDetailService.updateWasterItemQuantityIng(obj.getOriginNo(),obj.getOriginSerialNo(),obj.getOrigin(),obj.getEnterpriseNo(),obj.getItemAmount());
			}
		}
		

		///////////////////////////////////////////////////////////////////////
		//销售发货单（XSCK）
		///////////////////////////////////////////////////////////////////////
		if (obj.getBillType().equals("XSCK")){
			if ("XSDD".equals(obj.getOrigin())){
				//如果数据来源是销售订单，则更新正在发货数量
				//插入
				saleOrderService.updatePickItemQuantityIng(
						obj.getOriginNo()
						,obj.getOriginSerialNo()
						,obj.getEnterpriseNo()
						,obj.getItemAmount()
						,obj.getWasterAmount()
						,obj.getUllageAmount()
						,obj.getArriveAmountBack()
						);
			}
		}
		
		return 0;
	}

	//撤回
	@Transactional
	private int recallRelation(StorageRecordDetail obj){

		//TODO 退库处理
		if ((obj.getBillType().equals("XSRK") && obj.getOrigin().equals("XSCK"))){
			storageRecordDetailService.updateBackItemQuantityIng(
						obj.getOriginNo()
						,obj.getOriginSerialNo()
						,obj.getOrigin()
						,obj.getEnterpriseNo()
						,obj.getItemAmount().negate()
						,obj.getWasterAmount().negate()
						,obj.getUllageAmount().negate()
						,obj.getArriveAmountBack().negate()
						);
		}
		
		//TODO 报废处理
		
		if (obj.getBillType().equals("BFDJ")){
			if (obj.getOrigin().equals("XSRK")){
				
				//更新正在处理废品数量
				storageRecordDetailService.updateWasterItemQuantityIng(obj.getOriginNo(),obj.getOriginSerialNo(),obj.getOrigin(),obj.getEnterpriseNo(),obj.getItemAmount());
			}
		}
		

		///////////////////////////////////////////////////////////////////////
		//销售发货单（XSCK）
		///////////////////////////////////////////////////////////////////////
		if (obj.getBillType().equals("XSCK")){
			if ("XSDD".equals(obj.getOrigin())){
				//如果数据来源是销售订单，则更新正在发货数量
				//插入
				saleOrderService.updatePickItemQuantityIng(
						obj.getOriginNo()
						,obj.getOriginSerialNo()
						,obj.getEnterpriseNo()
						,obj.getItemAmount().negate()
						,obj.getWasterAmount().negate()
						,obj.getUllageAmount().negate()
						,obj.getArriveAmountBack().negate()
						);
			}
		}
 		
		return 0;
	}

	@Transactional
	private int doItStorage(StorageRecordDetail srd, String userId) {
		// TODO Auto-generated method stub
//		System.out.println("doIt.billType-->"+srd.getBillType());
//		System.out.println("doIt.getAccountQuantityI-->"+srd.getAccountQuantityI());
//		System.out.println("doIt.getAccountQuantityO-->"+accountQuantity);
		
		//调用入库类，提交单据
		
		FileItem fileItem = fileItemService.getByID(srd.getItemID());
		if(fileItem==null){
			return -1;
		}
		
//		if(fileItem.getCheckin()==0) {
//			//无需出入库登记
//			return 0;
//		}
		
		//系统参数设置
		ParamSetting paramSetting = paramSettingService.getByNo(srd.getEnterpriseNo());
		//采用成本制度【0：标准成本制，1：实际成本制】
		int costingRules = 1;
		//实际成本制：1、移动加权平均，2、月末加权平均，3、先进先出，4、个别计价（分批认定）
		int costingType = 1;
		if(paramSetting!=null) {
			costingRules = paramSetting.getCostingRules();
			costingType = paramSetting.getCostingType();
		}
		
		/*
		$scope.dataCostingType = [
		              			{"costingType":1,"costingTypeLabel":"1:移动加权平均"}
		              			,{"costingType":2,"costingTypeLabel":"2:月末一次加权加权平均"}
								,{"costingType":3,"costingTypeLabel":"3:先进先出X"}
								,{"costingType":4,"costingTypeLabel":"4:个别计价（分批认定）X"}
		              			];
		*/
		//成本计价方式
//		int costingType = paramSetting.getCostingType();
		
		//成本计价方式
//		int costingType = fileItem.getCostingType();
//		System.out.println("成本计价方式costingType-->>"+costingType);
		
		/*
		//1：入库，2：销货，3：领用，4：调拨，5：调整。
		int dealType = 0;
		//影响成本码
		String costingCode = null;
		
		String billType = srd.getBillType();
		String enterpriseNo = srd.getEnterpriseNo();
		BillSettingOrg billSettingOrg = billSettingOrgService.getByNo(billType, enterpriseNo);
		if(billSettingOrg!=null) {
			dealType = billSettingOrg.getDealType();
			costingCode = billSettingOrg.getCostingCode();
		}else {
			BillSetting billSetting = billSettingService.getByNo(billType);
			if(billSetting==null) {
				return -99;
			}else {
				dealType = billSetting.getDealType();
				costingCode = billSetting.getCostingCode();
			}
		}
		*/

		String itemID = srd.getItemID();
		String revOpay = srd.getRevOpay();

		//数量（账）
		BigDecimal accountQuantity = srd.getItemAmount().multiply(new BigDecimal(srd.getDirection())).setScale(2, RoundingMode.HALF_UP);
		//件数（账）
		BigDecimal accountPieceQuantity = srd.getPieceQuantity().multiply(new BigDecimal(srd.getDirection())).setScale(2, RoundingMode.HALF_UP);
		
		//////////登记明细账是公用参数
		BigDecimal itemQuantity = accountQuantity;
		BigDecimal pieceQuantity = accountPieceQuantity;
		String batchNo = srd.getBatchNo();
		String batchDescribe = srd.getBatchDescribe();

		String storeNo = srd.getStoreNo();
		String projectNo = srd.getProjectNo();
		
		int frozenFlag = srd.getFrozenFlag();

		String enterpriseNo = srd.getEnterpriseNo();
		String enterpriseName = srd.getEnterpriseName();
		
		String recordNo = srd.getRecordNo();
		String serialNo = srd.getSerialNo();
		String fMasterID = srd.getfMasterID();
		
		String systemCode = srd.getSystemCode();
		String billType = srd.getBillType();
		String billTypeName = srd.getBillTypeName();
		int dealType = srd.getDealType();
		String costingCode = srd.getCostingCode();

		Date orderDate = srd.getOrderDate();

		String itemNo = srd.getItemNo();
		String itemName = srd.getItemName();
		String itemProperty = srd.getItemProperty();
		
		String unitCode = srd.getUnitCode();
		String unitName = srd.getUnitName();
		
		int validDays = srd.getValidDays();
		int checkoutAgainDays = srd.getCheckoutAgainDays();

		Date produceDate = srd.getProduceDate();
		Date validDate = srd.getValidDate();
		Date checkoutAgainDate = srd.getCheckoutAgainDate();
		String workNo = srd.getWorkNo();
		
		String storageTypeD = srd.getStorageTypeD();
		String storageTypeDLabel = srd.getStorageTypeDLabel();
		String providerID = srd.getProviderID();
		String providerNo = srd.getProviderNo();
		String shortName = srd.getShortName();
		String providerName = srd.getProviderName();
		
		String storageType = srd.getStorageType();
		String storageTypeLabel = srd.getStorageTypeLabel();
		String storageID = srd.getStorageID();
		String storageNo = srd.getStorageNo();
		String storageName = srd.getStorageName();
		String floorNo = srd.getFloorNo();
		//////////////////////////////////////////////
		
		
		////////////////入库金额（账）/////////////////////////////
		//入账单位成本
		BigDecimal materialAmountPer = BigDecimal.ZERO;
		BigDecimal workingAmountPer = BigDecimal.ZERO;
		BigDecimal manufactAmountPer = BigDecimal.ZERO;
		BigDecimal processAmountPer = BigDecimal.ZERO;
		BigDecimal costingAmountPer = BigDecimal.ZERO;
		
		//标准成本制
		if(costingRules==0) {
			materialAmountPer = fileItem.getMaterialStandardPer();
			workingAmountPer = fileItem.getWorkingStandardPer();
			manufactAmountPer = fileItem.getManufactStandardPer();
			processAmountPer = fileItem.getProcessStandardPer();
			costingAmountPer = materialAmountPer.add(workingAmountPer).add(manufactAmountPer).add(processAmountPer);
		}
		
		BigDecimal materialAmount = BigDecimal.ZERO;
		BigDecimal workingAmount = BigDecimal.ZERO;
		BigDecimal manufactAmount = BigDecimal.ZERO;
		BigDecimal processAmount = BigDecimal.ZERO;
		BigDecimal costingAmount = BigDecimal.ZERO;
		

		//TODO:一、处理入库
		//TODO 入库单/////////////////////////////////////////////////////////////////////////
		

		//TODO:二、处理出库
		/////////////////////////////////////////////////////////////////////////////////
		/////////////////(转出仓库：providerNo，转入仓库：storageNo)//////////////////////
		/////////////////////////////////////////////////////////////////////////////////
		//TODO 出库单/////////////////////////////////////////////////////////////////////////
		///////////////////////////////////////////////////////////////////////
		//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<销售发货单（XSCK）
		///////////////////////////////////////////////////////////////////////
		if (srd.getBillType().equals("XSCK") || srd.getBillType().equals("XSRK")){
			
			//int mainFlag = 1; //是否更新物料档案: 0:不更新,1:更新.
			//String storageID = srd.getStorageID();

			////////////////出库金额（账）/////////////////////////////
			
			//实际成本制：1、移动加权平均，2、月末加权平均，3、先进先出，4、个别计价（分批认定）
			if(costingRules==1) {
				switch(costingType) {
					case 1://1、移动加权平均
						if(srd.getBillType().equals("XSCK") || srd.getBillType().equals("XSRK")){
							//销货单或者退货单
							//单位成本使用实际单位成本：物料仓库档案中的实际单位成本
							//出库时：物料仓库档案的出库成本与物料档案的出库单位成本不同，但是出库成本相同。
							StorageItem storageItem = storageItemService.getByNo(storageID, srd.getItemID());
							if(storageItem!=null) {
								if(storageItem.getItemQuantityL().compareTo(BigDecimal.ZERO)!=0) {
									materialAmountPer = storageItem.getCostingAmount().divide(storageItem.getItemQuantityL(), 6, RoundingMode.HALF_UP);
								}
							}
							workingAmountPer = BigDecimal.ZERO;
							manufactAmountPer = BigDecimal.ZERO;
							processAmountPer = BigDecimal.ZERO;
							costingAmountPer = materialAmountPer.add(workingAmountPer).add(manufactAmountPer).add(processAmountPer);
						}else {
							//其他类型出库单据，其他出库单
							//成本由前端单据录入，无需在此处处理
							//单位成本使用实际单位成本：（未税金额 - 扣款金额）/入库数量
							if(accountQuantity.compareTo(BigDecimal.ZERO)!=0){
								materialAmountPer = (srd.getOrderAmountOld().subtract(srd.getDiscountAmount())).divide(accountQuantity, 6, RoundingMode.HALF_UP);
							}
							workingAmountPer = BigDecimal.ZERO;
							manufactAmountPer = BigDecimal.ZERO;
							processAmountPer = BigDecimal.ZERO;
							costingAmountPer = materialAmountPer.add(workingAmountPer).add(manufactAmountPer).add(processAmountPer);
						}
						break;
					case 2://2、月末加权平均
						
						break;
					case 3://3、先进先出
						
						break;
					case 4://4、个别计价（分批认定）
						
						break;
					default:
						System.out.println("未知存货计价方式！");
				}
			}
			
			//金额
			materialAmount = materialAmountPer.multiply(accountQuantity).setScale(2,BigDecimal.ROUND_HALF_UP);
			workingAmount = workingAmountPer.multiply(accountQuantity).setScale(2,BigDecimal.ROUND_HALF_UP);
			manufactAmount = manufactAmountPer.multiply(accountQuantity).setScale(2,BigDecimal.ROUND_HALF_UP);
			processAmount = processAmountPer.multiply(accountQuantity).setScale(2,BigDecimal.ROUND_HALF_UP);
			costingAmount = materialAmount.add(workingAmount).add(manufactAmount).add(processAmount);
			
			//////////////////////////////////////////////////////////
		
		}
				
		//库存记账（审核）
		inventoryService.postingExt(recordNo, serialNo, fMasterID, systemCode, billType, billTypeName, revOpay, costingCode, dealType, orderDate, storageTypeD, storageTypeDLabel, providerID, providerNo, shortName, providerName, storageType, storageTypeLabel, storageID, storageNo, storageName, floorNo, itemID, itemNo, itemName, itemProperty, unitCode, unitName, validDays, checkoutAgainDays, itemQuantity, pieceQuantity, materialAmountPer, workingAmountPer, manufactAmountPer, processAmountPer, costingAmountPer, materialAmount, workingAmount, manufactAmount, processAmount, costingAmount, batchNo, batchDescribe, produceDate, validDate, checkoutAgainDate, storeNo, projectNo, workNo, frozenFlag, userId, enterpriseNo, enterpriseName);
		
		return 0;
	}

	@Transactional
	private int unDoStorage(StorageRecordDetail srd, String userId) {
		
		String revOpay = srd.getRevOpay();
		String recordNo = srd.getRecordNo();
		String serialNo = srd.getSerialNo();
		String enterpriseNo = srd.getEnterpriseNo();
		//库存反记账（撤销审核）
		inventoryService.unpostingExt(recordNo, serialNo, revOpay, userId, enterpriseNo);
		
		return 0;
	}

	@Transactional
	private int doItRelation(StorageRecordDetail srd){

		//TODO：八、处理关联单据

		//TODO 五、退库处理
		if ((srd.getBillType().equals("XSRK") && srd.getOrigin().equals("XSCK"))){
		
			if(srd.getOrigin()!=null && srd.getOriginNo()!=null){

				storageRecordDetailService.updateBackItemQuantity(
						srd.getOriginNo()
						,srd.getOriginSerialNo()
						,srd.getOrigin()
						,srd.getEnterpriseNo()
						,srd.getItemAmount()
						,srd.getWasterAmount()
						,srd.getUllageAmount()
						,srd.getArriveAmountBack()
						,srd.getPieceQuantity()
						);
				
			}
			
			//TODO：处理退库单关联单据（订单）
			//销售订单
			if(srd.getBillType().equals("XSRK")){
				if(srd.getOrderNo()!=null && !"".equals(srd.getOrderNo())){
					//workNo为销售订单号
					String workSerialNo = srd.getProcedureStep();
					saleOrderService.updateBackItemQuantity(srd.getOrderNo(),workSerialNo ,srd.getEnterpriseNo() ,srd.getItemAmount() ,srd.getPieceQuantity());
				}
			}
		}	
		
		//TODO 六、报废处理（报废单关联单据处理）
		if (srd.getBillType().equals("BFDJ")){
			if (srd.getOrigin().equals("XSRK")){
				//更新废品处理数量
				storageRecordDetailService.updateWasterItemQuantity(srd.getOriginNo(),srd.getOriginSerialNo(),srd.getOrigin(),srd.getEnterpriseNo(),srd.getItemAmount(),srd.getPieceQuantity());
			}
		}
		

		///////////////////////////////////////////////////////////////////////
		//销售发货单（XSCK）
		///////////////////////////////////////////////////////////////////////
		if (srd.getBillType().equals("XSCK")){
			//如果是销售单的数据，则更新销售单的发货数量
			if ("XSDD".equals(srd.getOrigin()) && srd.getOriginNo()!=null){
				saleOrderService.updatePickItemQuantity(
						srd.getOriginNo()
						,srd.getOriginSerialNo()
						,srd.getEnterpriseNo()
						,srd.getItemAmount()
						,srd.getWasterAmount()
						,srd.getUllageAmount()
						,srd.getArriveAmountBack()
						,srd.getPieceQuantity()
						);
			}		
		}
		return 0;
	}

	@Transactional
	private int unDoRelation(StorageRecordDetail srd){

		//TODO：八、处理相关单据
		
		//TODO 五、退库处理
	if ((srd.getBillType().equals("XSRK") && srd.getOrigin().equals("XSCK"))){
			if(srd.getOrigin()!=null && srd.getOriginNo()!=null){
				
			storageRecordDetailService.updateBackItemQuantity(
						srd.getOriginNo()
						,srd.getOriginSerialNo()
						,srd.getOrigin()
						,srd.getEnterpriseNo()
						,srd.getItemAmount().negate()
						,srd.getWasterAmount().negate()
						,srd.getUllageAmount().negate()
						,srd.getArriveAmountBack().negate()
						,srd.getPieceQuantity().negate()
						);
				
			}
			//TODO：处理退库单关联单据（订单）
			//销售订单
			if(srd.getBillType().equals("XSRK")){
				if(srd.getOrderNo()!=null && !"".equals(srd.getOrderNo())){
					//workNo为销售订单号
					String workSerialNo = srd.getProcedureStep();
					saleOrderService.updateBackItemQuantity(srd.getOrderNo(),workSerialNo ,srd.getEnterpriseNo() ,srd.getItemAmount().negate() ,srd.getPieceQuantity().negate());
				}
			}
			
		}
		
		//TODO 六、报废处理（报废单关联单据处理）
		if (srd.getBillType().equals("BFDJ")){
			if (srd.getOrigin().equals("XSRK")){
				//更新废品处理数量
				storageRecordDetailService.updateWasterItemQuantity(srd.getOriginNo(),srd.getOriginSerialNo(),srd.getOrigin(),srd.getEnterpriseNo(),srd.getItemAmount().negate(),srd.getPieceQuantity().negate());
			}
		}

		///////////////////////////////////////////////////////////////////////
		//销售发货单（XSCK）
		///////////////////////////////////////////////////////////////////////
		if (srd.getBillType().equals("XSCK")){
			//如果是销售单的数据，则更新销售单的发货数量
			if ("XSDD".equals(srd.getOrigin()) && srd.getOriginNo()!=null){
				saleOrderService.updatePickItemQuantity(
						srd.getOriginNo()
						,srd.getOriginSerialNo()
						,srd.getEnterpriseNo()
						,srd.getItemAmount().negate()
						,srd.getWasterAmount().negate()
						,srd.getUllageAmount().negate()
						,srd.getArriveAmountBack().negate()
						,srd.getPieceQuantity().negate()
						);
			}
		}
		
		return 0;
	}

	////////////////////////////////////////////////////////////////////////////////////
	////////////////////////////////////////////////////////////////////////////////////
	////////////////////////////////////////////////////////////////////////////////////
	
	
	
	//退库
	@Transactional
	@Override
	public StorageRecord storageRecordBACKInsert(StorageRecord storageSource
			,String cUsercode,String cUsername,String userId,String autoState, int flowType, String autoPayment,String employeeNo,String employeeName){
		return inventoryService.storageRecordBACKInsert(storageSource, cUsercode, cUsername, userId, autoState, flowType, autoPayment, employeeNo, employeeName);
	}
	
	
	//提交出入库单
	@Override
	@Transactional
	public Map<String,Object> storageRecordConfirm(String rowID, String cUsercode, String cUsername, String userId, String employeeNo, String employeeName){
		
		StorageRecord obj = storageRecordService.getByID(rowID);
		
		MapMessage mapMessage = new MapMessage(obj.getfID(),obj.getRecordNo(),obj.getBillType(),obj.getBillTypeName()
				,MapMessage.STATUSINFO_SUCCESS_CODE//"http://www.iune.cn"
				,MapMessage.STATUSINFO_SUCCESS_MSG//"操作成功！"
				,MapMessage.STATUSINFO_SUCCESS_INFO//"操作成功！"
				,MapMessage.STATUSINFO_SUCCESS_FLAG//"success"
				);
		
		if("confirm".equals(obj.getAudit())){
			return mapMessage.toMap();
		}
		
		//验证数据完整性和有效性（同时可以验证库存是否不足）
		List<StorageRecordDetail> srds = storageRecordDetailService.getByMasterID(rowID);
		for(StorageRecordDetail srd:srds){
			//仓库数据有效性验证
			if("QTRK".equals(obj.getBillType()) || "QTCK".equals(obj.getBillType()) 
					|| "CBKZ".equals(obj.getBillType()) || "DBDJ".equals(obj.getBillType()) 
					|| "GYRK".equals(obj.getBillType()) || "GYCK".equals(obj.getBillType()) 
					|| "SCFL".equals(obj.getBillType()) || "SCTL".equals(obj.getBillType()) 
					|| "WWFL".equals(obj.getBillType()) || "WWTL".equals(obj.getBillType()) 
					) {
				String storageID = srd.getStorageID();
				FileStorage fileStorage = fileStorageService.getByID(storageID);
				if(fileStorage.getNodeKind()==null) {
					//不是末端仓库数据，不合法
					mapMessage.setStatusCode("100001");
					mapMessage.setStatusMsg(MapMessage.STATUSINFO_FAILURE_MSG);
					mapMessage.setStatusInfo("库存地不存在，无法撤销提交！");
					mapMessage.setStatusFlag(MapMessage.STATUSINFO_FAILURE_FLAG);
					return mapMessage.toMap();
				}
			}
		}
	
		//执行的相关联的单据更新
		for(StorageRecordDetail srd:srds){
			this.submitRelation(srd);
		}
	
		storageRecordDetailService.confirmByMasterID(rowID);
		
		//然后审核主表
		storageRecordService.confirm(rowID);
		
		//自动审核
		if(obj.getFlowType()==0){
			Map<String,Object> map = this.storageRecordAgreeIt(rowID, cUsercode, cUsername, userId, employeeNo, employeeName);
			mapMessage.fromMap(map);
		}
		
		return mapMessage.toMap();
	}

	//撤回出入库单
	@Override
	@Transactional
	public Map<String,Object> storageRecordActive(String rowID, String cUsercode, String cUsername, String userId, String employeeNo, String employeeName){
		StorageRecord obj = storageRecordService.getByID(rowID);
		
		MapMessage mapMessage = new MapMessage(obj.getfID(),obj.getRecordNo(),obj.getBillType(),obj.getBillTypeName()
				,MapMessage.STATUSINFO_SUCCESS_CODE//"http://www.iune.cn"
				,MapMessage.STATUSINFO_SUCCESS_MSG//"操作成功！"
				,MapMessage.STATUSINFO_SUCCESS_INFO//"操作成功！"
				,MapMessage.STATUSINFO_SUCCESS_FLAG//"success"
				);
	
		List<StorageRecordDetail> srds = storageRecordDetailService.getByMasterID(rowID);
		for(StorageRecordDetail srd:srds){
			//判断是否已经开具检验单
			if("XSRK".equals(srd.getBillType())) {
				//1:待验
				if (srd.getQualityType()>0 && srd.getQualityStatus()>1){
					mapMessage.setStatusCode("100001");
					mapMessage.setStatusMsg(MapMessage.STATUSINFO_FAILURE_MSG);
					mapMessage.setStatusInfo("单据已检验，无法撤销提交！");
					mapMessage.setStatusFlag(MapMessage.STATUSINFO_FAILURE_FLAG);
					return mapMessage.toMap();
				}
			}
		}
		
	
		//执行的相关联的单据更新
		for(StorageRecordDetail srd:srds){
			this.recallRelation(srd);
		}
	
		//首先审核从表
		storageRecordDetailService.activeByMasterID(rowID);
		
		//然后审核主表
		storageRecordService.active(rowID);
		
		return mapMessage.toMap();
	}

	//审核出入库单（改造为主从表不关联审核）
	@Override
	@Transactional
	public Map<String,Object> storageRecordAgreeIt(String rowID, String cUsercode, String cUsername, String userId, String employeeNo, String employeeName){
		
		StorageRecord sr = storageRecordService.getByID(rowID);

		MapMessage mapMessage = new MapMessage(sr.getfID(),sr.getRecordNo(),sr.getBillType(),sr.getBillTypeName()
				,MapMessage.STATUSINFO_SUCCESS_CODE//"http://www.iune.cn"
				,MapMessage.STATUSINFO_SUCCESS_MSG//"操作成功！"
				,MapMessage.STATUSINFO_SUCCESS_INFO//"操作成功！"
				,MapMessage.STATUSINFO_SUCCESS_FLAG//"success"
				);
		
		//判断检验状态
		
		List<StorageRecordDetail> srds = storageRecordDetailService.getByMasterID(rowID);
		//判断批号是否存在，判断库存为负控制
		
		
		//判断检验状态
		/*
		检验单
		检验方式
		0:免检
		1:抽检（减量）
		2:抽检（正常）
		3:抽检（加严）
		4:全检
		 */
		//var qualityType = dataDetail.getValue('qualityType',rowID);
		/*
		入库单	检验单
		检验状态	判定
		1:待验	
		2:合格	2:允收
		3:不良	3:拒收
		4:特采	4:特采
			
		9:在验	9:在验
		 */
		//var qualityStatus = dataDetail.getValue('qualityStatus',rowID);
		
		//然后检查子表
		for(StorageRecordDetail srd : srds){
			//判断库存是否可以为负数
			//判断是否库存量充足
			//检测范围：销售发货单，发料单，采购、委外、生产、工艺入库退回单
			if(srd.getBillType().equals("XSCK")){
				if("no".equals(srd.getProcedureStep())) {
					//不允许
					BigDecimal quantityL = BigDecimal.ZERO;
					StorageItem si = storageItemService.getByNo(srd.getStorageID(), srd.getItemID());
					if(si==null){
						quantityL = new BigDecimal(0);
					}else{
						quantityL = si.getItemQuantityL();
					}
					
					if (quantityL.compareTo(srd.getItemAmount())<0){
						//库存数量小于零
						mapMessage.setStatusCode("100003");
						mapMessage.setStatusMsg(MapMessage.STATUSINFO_FAILURE_MSG);
						mapMessage.setStatusInfo("单据存在库存不足项目，无法审核！");
						mapMessage.setStatusFlag(MapMessage.STATUSINFO_FAILURE_FLAG);
						return mapMessage.toMap();
					}
				}
			}
			//判断是否已经检验
			if(srd.getBillType().equals("XSRK")){
				if (srd.getQualityStatus()==1 || srd.getQualityStatus()==9){
					//待验或者在验
					mapMessage.setStatusCode("100001");
					mapMessage.setStatusMsg(MapMessage.STATUSINFO_FAILURE_MSG);
					mapMessage.setStatusInfo("单据存在待检验项目，无法审核！");
					mapMessage.setStatusFlag(MapMessage.STATUSINFO_FAILURE_FLAG);
					return mapMessage.toMap();
				}
			}
		}
		

		//首先审核从表
//		storageRecordDetailService.agreeItByMasterID(rowID);
		for(StorageRecordDetail srd : srds){
			
			srd.setAudit("confirm");
			srd.setConfirmDate(Utils.getCurrentDate());
			
			srd.setResultStatus("已审核");
//			dao.update(srd);
			//执行更新操作
			if(srd.getCheckin()==1) {
				//需要出入库登记
				this.doItStorage(srd, userId);//库存数量更新
			}
			
			this.doItRelation(srd);//关联单据更新
		}

		
		//然后审核主表
		storageRecordService.agreeIt(rowID,cUsercode,cUsername,userId);
		if(sr.getBillType().equals("XSCK")) {
			//销售发货单
			//更新最近交易时间
			String customerID = sr.getProviderID();
			if(customerID!=null){
				FileCustomer fileCustomer = fileCustomerService.getByID(customerID);
				if(fileCustomer!=null){
					fileCustomerService.updateDealDateLast(fileCustomer,sr.getConfirmDate());
				}
			}			
		}
		
		
		//然后审核主表
		storageRecordService.agreeIt(rowID, cUsercode, cUsername, userId);

//		Map<String,Object> map = mapMessage.toMap();
		
		return mapMessage.toMap();

	}

	//反审核出入库单
	@Override
	@Transactional
	public Map<String,Object> storageRecordUnAgree(String rowID,String cUsercode,String cUsername, String userId, String employeeNo, String employeeName){
		//判断是否可以撤销
		
		StorageRecord sr = storageRecordService.getByID(rowID);
		MapMessage mapMessage = new MapMessage(sr.getfID(),sr.getRecordNo(),sr.getBillType(),sr.getBillTypeName()
				,MapMessage.STATUSINFO_SUCCESS_CODE//"http://www.iune.cn"
				,MapMessage.STATUSINFO_SUCCESS_MSG//"操作成功！"
				,MapMessage.STATUSINFO_SUCCESS_INFO//"操作成功！"
				,MapMessage.STATUSINFO_SUCCESS_FLAG//"success"
				);

		
		List<StorageRecordDetail> srds = storageRecordDetailService.getByMasterID(rowID);
		//然后检查子表
		for(StorageRecordDetail srd : srds){
			
			//销售发货单
			if(srd.getBillType().equals("XSCK")){
				//判断是否已经开票，或者正在开票
				if (srd.getInvoiceQuantityIng().compareTo(BigDecimal.ZERO)!=0 || srd.getInvoiceQuantity().compareTo(BigDecimal.ZERO)!=0){
					mapMessage.setStatusCode("100001");
					mapMessage.setStatusMsg(MapMessage.STATUSINFO_FAILURE_MSG);
					mapMessage.setStatusInfo("单据已开票，无法撤销审核！");
					mapMessage.setStatusFlag(MapMessage.STATUSINFO_FAILURE_FLAG);
				}
				//检查结果是否包括失败状态，如果包括，直接返回
				if (mapMessage.getStatusFlag().equals(MapMessage.STATUSINFO_FAILURE_FLAG)){
					return mapMessage.toMap();
				}
				//判断是否已经退货，或者正在退货
				if (srd.getBackItemIng().compareTo(BigDecimal.ZERO)!=0 || srd.getBackItemAmount().compareTo(BigDecimal.ZERO)!=0){
					mapMessage.setStatusCode("100001");
					mapMessage.setStatusMsg(MapMessage.STATUSINFO_FAILURE_MSG);
					mapMessage.setStatusInfo("单据已退货，无法撤销审核！");
					mapMessage.setStatusFlag(MapMessage.STATUSINFO_FAILURE_FLAG);
				}
				//检查结果是否包括失败状态，如果包括，直接返回
				if (mapMessage.getStatusFlag().equals(MapMessage.STATUSINFO_FAILURE_FLAG)){
					return mapMessage.toMap();
				}
			}
			
			//销售退货单
			if(srd.getBillType().equals("XSRK")){

				//判断是否已经开票，或者正在开票
				if (srd.getInvoiceQuantityIng().compareTo(BigDecimal.ZERO)!=0 || srd.getInvoiceQuantity().compareTo(BigDecimal.ZERO)!=0){
					mapMessage.setStatusCode("100001");
					mapMessage.setStatusMsg(MapMessage.STATUSINFO_FAILURE_MSG);
					mapMessage.setStatusInfo("单据已开票，无法撤销审核！");
					mapMessage.setStatusFlag(MapMessage.STATUSINFO_FAILURE_FLAG);
				}
				//检查结果是否包括失败状态，如果包括，直接返回
				if (mapMessage.getStatusFlag().equals(MapMessage.STATUSINFO_FAILURE_FLAG)){
					return mapMessage.toMap();
				}
				
			}
			
		}
	
//		storageRecordDetailService.unAgreeByMasterID(rowID);
		for(StorageRecordDetail srd : srds){

			srd.setAudit("active");
			srd.setConfirmDate(null);
			
			srd.setResultStatus("审核中");
//			dao.update(srd);
			//执行更新操作
			if(srd.getCheckin()==1) {
				//需要出入库登记
				this.unDoStorage(srd, userId);//库存数量更新
			}
			
			this.unDoRelation(srd);//关联单据更新
		}
		
		//然后审核主表
		storageRecordService.unAgree(rowID);
		
		return mapMessage.toMap();

	}

	//关闭出入库单
	@Override
	@Transactional
	public Map<String,Object> storageRecordClose(String rowID, String cUsercode, String cUsername, String userId, String employeeNo, String employeeName){
		StorageRecord obj = storageRecordService.getByID(rowID);
		
		MapMessage mapMessage = new MapMessage(obj.getfID(),obj.getRecordNo(),obj.getBillType(),obj.getBillTypeName()
				,MapMessage.STATUSINFO_SUCCESS_CODE//"http://www.iune.cn"
				,MapMessage.STATUSINFO_SUCCESS_MSG//"操作成功！"
				,MapMessage.STATUSINFO_SUCCESS_INFO//"操作成功！"
				,MapMessage.STATUSINFO_SUCCESS_FLAG//"success"
				);

		//首先审核从表
//		StorageRecordDetailUtil srdu = new StorageRecordDetailUtil();
		int rtn = storageRecordDetailService.closeByMasterID(rowID);
		if (rtn != 0){
			mapMessage.setStatusCode(MapMessage.STATUSINFO_FAILURE_CODE);
			mapMessage.setStatusMsg(MapMessage.STATUSINFO_FAILURE_MSG);
			mapMessage.setStatusInfo(MapMessage.STATUSINFO_FAILURE_INFO);
			mapMessage.setStatusFlag(MapMessage.STATUSINFO_FAILURE_FLAG);
			return mapMessage.toMap();
		}
		
		//然后审核主表
//		StorageRecordUtil sru = new StorageRecordUtil();
		rtn = storageRecordService.close(rowID);
		if (rtn != 0){
			mapMessage.setStatusCode(MapMessage.STATUSINFO_FAILURE_CODE);
			mapMessage.setStatusMsg(MapMessage.STATUSINFO_FAILURE_MSG);
			mapMessage.setStatusInfo(MapMessage.STATUSINFO_FAILURE_INFO);
			mapMessage.setStatusFlag(MapMessage.STATUSINFO_FAILURE_FLAG);
			return mapMessage.toMap();
		}
		
		return mapMessage.toMap();
	}

	//打开出入库单
	@Override
	@Transactional
	public Map<String,Object> storageRecordOpen(String rowID, String cUsercode, String cUsername, String userId, String employeeNo, String employeeName){
		StorageRecord obj = storageRecordService.getByID(rowID);
		
		MapMessage mapMessage = new MapMessage(obj.getfID(),obj.getRecordNo(),obj.getBillType(),obj.getBillTypeName()
				,MapMessage.STATUSINFO_SUCCESS_CODE//"http://www.iune.cn"
				,MapMessage.STATUSINFO_SUCCESS_MSG//"操作成功！"
				,MapMessage.STATUSINFO_SUCCESS_INFO//"操作成功！"
				,MapMessage.STATUSINFO_SUCCESS_FLAG//"success"
				);

		//首先审核从表
//		StorageRecordDetailUtil srdu = new StorageRecordDetailUtil();
		int rtn = storageRecordDetailService.openByMasterID(rowID);
		if (rtn != 0){
			mapMessage.setStatusCode(MapMessage.STATUSINFO_FAILURE_CODE);
			mapMessage.setStatusMsg(MapMessage.STATUSINFO_FAILURE_MSG);
			mapMessage.setStatusInfo(MapMessage.STATUSINFO_FAILURE_INFO);
			mapMessage.setStatusFlag(MapMessage.STATUSINFO_FAILURE_FLAG);
			return mapMessage.toMap();
		}
		
		//然后审核主表
//		StorageRecordUtil sru = new StorageRecordUtil();
		rtn = storageRecordService.open(rowID);
		if (rtn != 0){
			mapMessage.setStatusCode(MapMessage.STATUSINFO_FAILURE_CODE);
			mapMessage.setStatusMsg(MapMessage.STATUSINFO_FAILURE_MSG);
			mapMessage.setStatusInfo(MapMessage.STATUSINFO_FAILURE_INFO);
			mapMessage.setStatusFlag(MapMessage.STATUSINFO_FAILURE_FLAG);
			return mapMessage.toMap();
		}
		
		return mapMessage.toMap();
	}

	//销售发货单/采购退货单/委外退货单打印
	@Override
	public void invXSCKPrintPDF(String fID, Document doc) throws Exception {
		
//	@Test
//	public void storageRecordPrintPDF() throws Exception {
//		System.out.println("fID-->"+id);
		
//	    Document doc = new Document();// 创建一个PDF文档，我们的PDF内容都写在上面
	    
//	    PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(new File("c://pdftest//storageRecord.pdf"))); // 将pdf文档写入文件

//		String fID = "bf61ec2bc8163a3ad3d8572ad2fee7c6";
		StorageRecord storageRecord = storageRecordService.getByID(fID);
	   
//	    response.setContentType("application/pdf");
//	    PdfWriter.getInstance(doc, response.getOutputStream());
//	    
//	    doc.open();
	    
	    Font fontEN = new Font(BaseFont.createFont(),9);
	    BaseFont baseFont = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);  	    
//	    Font font = new Font(baseFont, 10, Font.ITALIC);
	    Font fontCN = new Font(baseFont, 9);
	    Paragraph pEnterpriseName = new Paragraph(storageRecord.getEnterpriseName(),fontCN);
	    // 居中显示
	    pEnterpriseName.setAlignment(Element.ALIGN_CENTER);
	    pEnterpriseName.setSpacingAfter(-10);
	    Paragraph pBillTypeName = new Paragraph(storageRecord.getBillTypeName(),new Font(baseFont,20));
	    // 居中显示
	    pBillTypeName.setAlignment(Element.ALIGN_CENTER);
	    LineSeparator line = new LineSeparator(1f, 100, BaseColor.BLACK, Element.ALIGN_CENTER, -5f);

	    
	    
	    
	    
	    
	    doc.add(pEnterpriseName);
	    doc.add(pBillTypeName);
	    doc.add(line);
	    
	    
        PdfPTable masterHead = new PdfPTable(8);
        
//        masterHead.setTotalWidth(new float[]{60, 200, 60, 200});
        masterHead.setTotalWidth(new float[]{45, 85, 45, 85, 45, 85, 45, 85});
        masterHead.setLockedWidth(true);
        masterHead.setSpacingBefore(10);
        
        PdfPCell ordrDateCell = new PdfPCell(new Phrase("单据日期:", fontCN));
        ordrDateCell.setUseBorderPadding(true);
        //
        // Setting cell's border width and color
        //
        ordrDateCell.setBorderWidth(0f);
//        ordrDateCell.setBorderColor(BaseColor.BLUE);
        masterHead.addCell(ordrDateCell);

        PdfPCell ordrDateValue = new PdfPCell(new Phrase(storageRecord.getOrderDate().toString(), fontEN));
        ordrDateValue.setUseBorderPadding(true);
        ordrDateValue.setBorderWidth(0f);
        //
        // Setting cell's background color
        //
//        cell2.setBackgroundColor(BaseColor.GRAY);
        //
        // Setting cell's individual border color
        //
//        cell2.setBorderWidthTop(1f);
//        cell2.setBorderColorTop(BaseColor.RED);
//        cell2.setBorderColorRight(BaseColor.GREEN);
//        cell2.setBorderColorBottom(BaseColor.BLUE);
//        cell2.setBorderColorLeft(BaseColor.BLACK);
        masterHead.addCell(ordrDateValue);

        PdfPCell auditCell = new PdfPCell(new Phrase("单据状态:", fontCN));
        auditCell.setUseBorderPadding(true);
        auditCell.setBorderWidth(0f);
        //
        // Setting cell's individual border width
        //
//        cell3.setBorderWidthTop(2f);
//        cell3.setBorderWidthRight(1f);
//        cell3.setBorderWidthBottom(2f);
//        cell3.setBorderWidthLeft(1f);
        masterHead.addCell(auditCell);

        String auditStatus = "待审核";
        String audit = storageRecord.getAudit();
        String state = storageRecord.getState();
        if(audit.equals("confirm")){
        	auditStatus = "已审核";
        }else if(audit.equals("active") && state.equals("confirm")){
        	auditStatus = "审核中";
        }else{
        	auditStatus = "待审核";
        }
        
       PdfPCell auditValue = new PdfPCell(new Phrase(auditStatus, fontCN));
       auditValue.setUseBorderPadding(true);
       auditValue.setBorderWidth(0f);
        //
        // Setting cell's individual border width
        //
//        cell4.setBorderWidthTop(2f);
//        cell4.setBorderWidthRight(1f);
//        cell4.setBorderWidthBottom(2f);
//        cell4.setBorderWidthLeft(1f);
        masterHead.addCell(auditValue);
        
        String providerNoLabel = "";
        String shortNameLabel = "";
        String providerNameLabel = "";
        
        if(storageRecord.getBillType().equals("CGCK") || storageRecord.getBillType().equals("WWCK")){
            
            providerNoLabel = "供方编码:";
            shortNameLabel = "供方简称:";
            providerNameLabel = "供方名称:";
        	
        }
        
        if(storageRecord.getBillType().equals("XSCK")){
            
            providerNoLabel = "客户编码:";
            shortNameLabel = "客户简称:";
            providerNameLabel = "客户名称:";
        	
        }
        
        PdfPCell providerNoCell = new PdfPCell(new Phrase(providerNoLabel, fontCN));
        providerNoCell.setBorder(0);
        masterHead.addCell(providerNoCell);
        PdfPCell providerNoValue = new PdfPCell(new Phrase(storageRecord.getProviderNo(), fontEN));
        providerNoValue.setBorder(0);
        masterHead.addCell(providerNoValue);
        
        PdfPCell shortNameCell = new PdfPCell(new Phrase(shortNameLabel, fontCN));
        shortNameCell.setBorder(0);
        masterHead.addCell(shortNameCell);
        PdfPCell shortNameValue = new PdfPCell(new Phrase(storageRecord.getShortName(), fontCN));
        shortNameValue.setBorder(0);
        masterHead.addCell(shortNameValue);

        //第一行结束
        masterHead.completeRow();
        
        PdfPCell orderNoCell = new PdfPCell(new PdfPCell(new Phrase("单号:", fontCN)));
        orderNoCell.setBorder(0);
        masterHead.addCell(orderNoCell);
        PdfPCell orderNoValue = new PdfPCell(new PdfPCell(new Phrase(storageRecord.getRecordNo(), fontEN)));
        orderNoValue.setBorder(0);
        orderNoValue.setColspan(3);
        masterHead.addCell(orderNoValue);
        
        PdfPCell providerNameCell = new PdfPCell(new Phrase(providerNameLabel, fontCN));
        providerNameCell.setBorder(0);
        masterHead.addCell(providerNameCell);
        PdfPCell providerNameValue = new PdfPCell(new Phrase(storageRecord.getProviderName(), fontCN));
        providerNameValue.setBorder(0);
        providerNameValue.setColspan(3);
        masterHead.addCell(providerNameValue);
        //第二行结束
        masterHead.completeRow();
        
        PdfPCell factoryNoCell = new PdfPCell(new PdfPCell(new Phrase("工厂编码:", fontCN)));
        factoryNoCell.setBorder(0);
        masterHead.addCell(factoryNoCell);
        PdfPCell factoryNoValue = new PdfPCell(new PdfPCell(new Phrase(storageRecord.getFactoryNo(), fontEN)));
        factoryNoValue.setBorder(0);
        masterHead.addCell(factoryNoValue);
        
        PdfPCell factoryNameCell = new PdfPCell(new PdfPCell(new Phrase("工厂名称:", fontCN)));
        factoryNameCell.setBorder(0);
        masterHead.addCell(factoryNameCell);
        PdfPCell factoryNameValue = new PdfPCell(new PdfPCell(new Phrase(storageRecord.getFactoryName(), fontCN)));
        factoryNameValue.setBorder(0);
        masterHead.addCell(factoryNameValue);
        
        PdfPCell invoiceCategoryLabelCell = new PdfPCell(new PdfPCell(new Phrase("发票类型:", fontCN)));
        invoiceCategoryLabelCell.setBorder(0);
        masterHead.addCell(invoiceCategoryLabelCell);
        PdfPCell invoiceCategoryLabelValue = new PdfPCell(new PdfPCell(new Phrase(storageRecord.getInvoiceCategoryLabel(), fontCN)));
        invoiceCategoryLabelValue.setBorder(0);
        masterHead.addCell(invoiceCategoryLabelValue);
        
        PdfPCell settleCategoryLabelCell = new PdfPCell(new Phrase("结算方式:", fontCN));
        settleCategoryLabelCell.setBorder(0);
        masterHead.addCell(settleCategoryLabelCell);
        PdfPCell settleCategoryLabelValue = new PdfPCell(new Phrase(storageRecord.getSettleCategoryLabel(), fontCN));
        settleCategoryLabelValue.setBorder(0);
        masterHead.addCell(settleCategoryLabelValue);
        //第三行结束
        masterHead.completeRow();
        
        PdfPCell taxTypeLabelCell = new PdfPCell(new PdfPCell(new Phrase("税种:", fontCN)));
        taxTypeLabelCell.setBorder(0);
        masterHead.addCell(taxTypeLabelCell);
        PdfPCell taxTypeLabelValue = new PdfPCell(new PdfPCell(new Phrase(storageRecord.getTaxTypeLabel(), fontCN)));
        taxTypeLabelValue.setBorder(0);
        masterHead.addCell(taxTypeLabelValue);
        
        PdfPCell taxRateCell = new PdfPCell(new PdfPCell(new Phrase("税率:", fontCN)));
        taxRateCell.setBorder(0);
        masterHead.addCell(taxRateCell);
        PdfPCell taxRateValue = new PdfPCell(new PdfPCell(new Phrase(storageRecord.getTaxRate().toString(), fontEN)));
        taxRateValue.setBorder(0);
        masterHead.addCell(taxRateValue);
        
        PdfPCell fAddressCell = new PdfPCell(new Phrase("地址:", fontCN));
        fAddressCell.setBorder(0);
        masterHead.addCell(fAddressCell);
        PdfPCell fAddressValue = new PdfPCell(new Phrase(storageRecord.getfAddress(), fontCN));
        fAddressValue.setBorder(0);
        fAddressValue.setColspan(3);
        masterHead.addCell(fAddressValue);
        //第四行结束
        masterHead.completeRow();
        
        PdfPCell employeeNameCell = new PdfPCell(new Phrase("经办人:", fontCN));
        employeeNameCell.setBorder(0);
        masterHead.addCell(employeeNameCell);
        PdfPCell employeeNameValue = new PdfPCell(new Phrase(storageRecord.getEmployeeName(), fontCN));
        employeeNameValue.setBorder(0);
        employeeNameValue.setColspan(3);
        masterHead.addCell(employeeNameValue);
        
        PdfPCell fAddressDetailCell = new PdfPCell(new Phrase("详细地址:", fontCN));
        fAddressDetailCell.setBorder(0);
        masterHead.addCell(fAddressDetailCell);
        PdfPCell fAddressDetailValue = new PdfPCell(new Phrase(storageRecord.getfAddressDetail(), fontCN));
        fAddressDetailValue.setBorder(0);
        fAddressDetailValue.setColspan(3);
        masterHead.addCell(fAddressDetailValue);
        //第五行结束
        masterHead.completeRow();
        
        PdfPCell shipperNameCell = new PdfPCell(new PdfPCell(new Phrase("物流公司:", fontCN)));
        shipperNameCell.setBorder(0);
        masterHead.addCell(shipperNameCell);
        PdfPCell shipperNameValue = new PdfPCell(new PdfPCell(new Phrase(storageRecord.getContacts(), fontCN)));
        shipperNameValue.setBorder(0);
        masterHead.addCell(shipperNameValue);
        
        PdfPCell waybillNoCell = new PdfPCell(new PdfPCell(new Phrase("运单号:", fontCN)));
        waybillNoCell.setBorder(0);
        masterHead.addCell(waybillNoCell);
        PdfPCell waybillNoValue = new PdfPCell(new PdfPCell(new Phrase(storageRecord.getContacts(), fontEN)));
        waybillNoValue.setBorder(0);
        masterHead.addCell(waybillNoValue);
        
        PdfPCell contactsCell = new PdfPCell(new Phrase("联系人:", fontCN));
        contactsCell.setBorder(0);
        masterHead.addCell(contactsCell);
        PdfPCell contactsValue = new PdfPCell(new Phrase(storageRecord.getContacts(), fontCN));
        contactsValue.setBorder(0);
        masterHead.addCell(contactsValue);
        
        PdfPCell mobilePhoneCell = new PdfPCell(new Phrase("联系电话:", fontCN));
        mobilePhoneCell.setBorder(0);
        masterHead.addCell(mobilePhoneCell);
        PdfPCell mobilePhoneValue = new PdfPCell(new Phrase(storageRecord.getMobilePhone(), fontEN));
        mobilePhoneValue.setBorder(0);
        masterHead.addCell(mobilePhoneValue);
        //第六行结束
        masterHead.completeRow();
        
        PdfPCell paymentTermLabelCell = new PdfPCell(new Phrase("付款条件:", fontCN));
        paymentTermLabelCell.setBorder(0);
        masterHead.addCell(paymentTermLabelCell);
        PdfPCell paymentTermLabelValue = new PdfPCell(new Phrase(storageRecord.getPaymentTermLabel(), fontCN));
        paymentTermLabelValue.setBorder(0);
        paymentTermLabelValue.setColspan(7);
        masterHead.addCell(paymentTermLabelValue);
        //第七行结束
        masterHead.completeRow();
        
        PdfPCell commentsCell = new PdfPCell(new Phrase("备注:", fontCN));
        commentsCell.setBorder(0);
        masterHead.addCell(commentsCell);
        PdfPCell commentsValue = new PdfPCell(new Phrase(storageRecord.getComments(), fontCN));
        commentsValue.setBorder(0);
        commentsValue.setColspan(7);
        masterHead.addCell(commentsValue);
        
        //第n行结束
        masterHead.completeRow();

        doc.add(masterHead);
//	    doc.add(line);
	    

        /*
        Image image = Image.getInstance("c://pdftest//smp.png");

        image.setAlignment(Image.ALIGN_RIGHT);
        // 设置边框
        image.setBorder(Image.BOX);
        image.setBorderWidth(2);
        image.setBorderColor(BaseColor.RED);
        // 设置图片大小
        
//        ScaleToFit有两个参数，指的是长和宽的最大值，但是图片的长宽比还是不会变的
//        ScaleAbsoluteHeight设置图片的高度，不管长宽比 ScaleAbsoluteWidth设置图片的宽度，不管长宽比
//        ScalePercent等比例缩放
        
//         image.scaleToFit(100, 100);
//         image.scaleAbsoluteHeight(100f);
//         image.scaleAbsoluteWidth(100f);

        image.scalePercent(50f);
        // 图片旋转30度
        image.setRotationDegrees(30);

        doc.add(image);
        */
        
        
        
        
        
	    //////////////////////////////////////////////////////////////////////////////////////////
	    
        PdfPTable details = new PdfPTable(8);
        details.setTotalWidth(new float[]{15, 70, 70, 80, 65, 75, 65, 80});//520
        details.setLockedWidth(true);
        details.setSpacingBefore(10);

        PdfPCell sharpCell = new PdfPCell(new Phrase("序号", fontCN));
//        sharpCell.setBorder(0);
        sharpCell.setRowspan(4);
        sharpCell.setHorizontalAlignment(Element.ALIGN_CENTER);
        sharpCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        details.addCell(sharpCell);

        PdfPCell itemNoCell = new PdfPCell(new Phrase("物料编码", fontCN));
//        itemNoCell.setBorder(0);
//        itemNoCell.setBorderWidthTop(0);
        itemNoCell.setBorderWidthLeft(0);
        itemNoCell.setBorderWidthBottom(0);
        itemNoCell.setBorderWidthRight(0);
        itemNoCell.setColspan(2);
        details.addCell(itemNoCell);

        PdfPCell projectNoCell = new PdfPCell(new Phrase("项目号", fontCN));
//        projectNoCell.setBorder(0);
        projectNoCell.setBorderWidthLeft(0);
        projectNoCell.setBorderWidthBottom(0);
        projectNoCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        details.addCell(projectNoCell);

        PdfPCell arriveAmountsCell = new PdfPCell(new Phrase("", fontCN));
//        arriveAmountsCell.setBorder(0);
        arriveAmountsCell.setBorderWidthLeft(0);
        arriveAmountsCell.setBorderWidthBottom(0);
        arriveAmountsCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        details.addCell(arriveAmountsCell);

        PdfPCell priceAmountCell = new PdfPCell(new Phrase("数量", fontCN));
//        priceAmountCell.setBorder(0);
        priceAmountCell.setBorderWidthLeft(0);
        priceAmountCell.setBorderWidthBottom(0);
        priceAmountCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        details.addCell(priceAmountCell);

        PdfPCell arriveAmountBackCell = new PdfPCell(new Phrase("", fontCN));
//        arriveAmountBackCell.setBorder(0);
        arriveAmountBackCell.setBorderWidthLeft(0);
        arriveAmountBackCell.setBorderWidthBottom(0);
        arriveAmountBackCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        details.addCell(arriveAmountBackCell);

        PdfPCell batchNoCell = new PdfPCell(new Phrase("批号", fontCN));
//        batchNoCell.setBorder(0);
        batchNoCell.setBorderWidthLeft(0);
        batchNoCell.setBorderWidthBottom(0);
        details.addCell(batchNoCell);
        
        details.completeRow();
        //第一行结束

        PdfPCell itemDescribeCell = new PdfPCell(new Phrase("名称", fontCN));
//        itemDescribeCell.setBorder(0);
        itemDescribeCell.setBorderWidthTop(0);
        itemDescribeCell.setBorderWidthLeft(0);
        itemDescribeCell.setBorderWidthBottom(0);
        itemDescribeCell.setColspan(3);
        details.addCell(itemDescribeCell);

        PdfPCell itemAmountsCell = new PdfPCell(new Phrase("", fontCN));
//        itemAmountsCell.setBorder(0);
        itemAmountsCell.setBorderWidthTop(0);
        itemAmountsCell.setBorderWidthLeft(0);
        itemAmountsCell.setBorderWidthBottom(0);
        itemAmountsCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        details.addCell(itemAmountsCell);

        PdfPCell pieceQuantityCell = new PdfPCell(new Phrase("件数", fontCN));
//        pieceQuantityCell.setBorder(0);
        pieceQuantityCell.setBorderWidthTop(0);
        pieceQuantityCell.setBorderWidthLeft(0);
        pieceQuantityCell.setBorderWidthBottom(0);
        pieceQuantityCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        details.addCell(pieceQuantityCell);

        PdfPCell orderAmountOldsCell = new PdfPCell(new Phrase("未税金额", fontCN));
//        orderAmountOldsCell.setBorder(0);
        orderAmountOldsCell.setBorderWidthTop(0);
        orderAmountOldsCell.setBorderWidthLeft(0);
        orderAmountOldsCell.setBorderWidthBottom(0);
        orderAmountOldsCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        details.addCell(orderAmountOldsCell);

        PdfPCell batchDescribeCell = new PdfPCell(new Phrase("批号说明", fontCN));
//        batchDescribeCell.setBorder(0);
        batchDescribeCell.setBorderWidthTop(0);
        batchDescribeCell.setBorderWidthLeft(0);
        batchDescribeCell.setBorderWidthBottom(0);
        details.addCell(batchDescribeCell);

        details.completeRow();
        //第二行结束

        PdfPCell itemPropertyCell = new PdfPCell(new Phrase("规格", fontCN));
//        itemPropertyCell.setBorder(0);
        itemPropertyCell.setBorderWidthTop(0);
        itemPropertyCell.setBorderWidthLeft(0);
        itemPropertyCell.setBorderWidthBottom(0);
        itemPropertyCell.setBorderWidthRight(0);
        itemPropertyCell.setColspan(2);
        details.addCell(itemPropertyCell);

        PdfPCell unitNameCell = new PdfPCell(new Phrase("单位", fontCN));
//        unitNameCell.setBorder(0);
        unitNameCell.setBorderWidthTop(0);
        unitNameCell.setBorderWidthLeft(0);
        unitNameCell.setBorderWidthBottom(0);
        unitNameCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        details.addCell(unitNameCell);

        PdfPCell discountRateCell = new PdfPCell(new Phrase("折扣率", fontCN));
//        discountRateCell.setBorder(0);
        discountRateCell.setBorderWidthTop(0);
        discountRateCell.setBorderWidthLeft(0);
        discountRateCell.setBorderWidthBottom(0);
        discountRateCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        details.addCell(discountRateCell);

        PdfPCell itemPriceCell = new PdfPCell(new Phrase("单价", fontCN));
//        itemPriceCell.setBorder(0);
        itemPriceCell.setBorderWidthTop(0);
        itemPriceCell.setBorderWidthLeft(0);
        itemPriceCell.setBorderWidthBottom(0);
        itemPriceCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        details.addCell(itemPriceCell);

        PdfPCell orderAmountTaxsCell = new PdfPCell(new Phrase("税额", fontCN));
//        orderAmountTaxsCell.setBorder(0);
        orderAmountTaxsCell.setBorderWidthTop(0);
        orderAmountTaxsCell.setBorderWidthLeft(0);
        orderAmountTaxsCell.setBorderWidthBottom(0);
        orderAmountTaxsCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        details.addCell(orderAmountTaxsCell);

        PdfPCell commentssCell = new PdfPCell(new Phrase("备注", fontCN));
//        commentssCell.setBorder(0);
        commentssCell.setBorderWidthTop(0);
        commentssCell.setBorderWidthLeft(0);
        commentssCell.setRowspan(2);
        details.addCell(commentssCell);

        details.completeRow();
        //第三行结束

        PdfPCell floorNoCell = new PdfPCell(new Phrase("库存地", fontCN));
//        floorNoCell.setBorder(0);
        floorNoCell.setBorderWidthTop(0);
        floorNoCell.setBorderWidthLeft(0);
        floorNoCell.setBorderWidthRight(0);
        floorNoCell.setColspan(2);
        details.addCell(floorNoCell);

        PdfPCell storageNoCell = new PdfPCell(new Phrase("仓库编码", fontCN));
//        storageNoCell.setBorder(0);
        storageNoCell.setBorderWidthTop(0);
        storageNoCell.setBorderWidthLeft(0);
        storageNoCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        details.addCell(storageNoCell);

        PdfPCell taxRatesCell = new PdfPCell(new Phrase("税率", fontCN));
//        taxRatesCell.setBorder(0);
        taxRatesCell.setBorderWidthLeft(0);
        taxRatesCell.setBorderWidthTop(0);
        taxRatesCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        details.addCell(taxRatesCell);

        PdfPCell orderAmountCell = new PdfPCell(new Phrase("金额", fontCN));
//        orderAmountCell.setBorder(0);
        orderAmountCell.setBorderWidthTop(0);
        orderAmountCell.setBorderWidthLeft(0);
        orderAmountCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        details.addCell(orderAmountCell);

        PdfPCell orderAmountTotalsCell = new PdfPCell(new Phrase("价税合计", fontCN));
//        orderAmountTotalsCell.setBorder(0);
        orderAmountTotalsCell.setBorderWidthTop(0);
        orderAmountTotalsCell.setBorderWidthLeft(0);
        orderAmountTotalsCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        details.addCell(orderAmountTotalsCell);

        details.completeRow();
        //第四行结束
        
        
//        doc.add(details);
        
        ////////////////////////////////////////////////////////////////////////////////////////////
        
        
	    //////////////////////////////////////////////////////////////////////////////////////////
        List<StorageRecordDetail> storageRecordDetails = storageRecordDetailService.getByMasterID(fID);
        if(storageRecordDetails.size()>0){
    	    
//            PdfPTable detailsValue = new PdfPTable(8);
//            
//            detailsValue.setTotalWidth(new float[]{20, 70, 70, 80, 80, 80, 60, 60});//520
//            detailsValue.setLockedWidth(true);
//            detailsValue.setSpacingBefore(10);
            
            for(int i=0;i<storageRecordDetails.size();i++){
            	StorageRecordDetail storageRecordDetail = storageRecordDetails.get(i);

            	//序号
            	String rowNo = String.valueOf(i+1);
                PdfPCell sharpValue = new PdfPCell(new Phrase(rowNo, fontEN));
//                sharpValue.setBorder(0);
                sharpValue.setBorderWidthTop(0);
                sharpValue.setRowspan(4);
                sharpValue.setHorizontalAlignment(Element.ALIGN_CENTER);
                sharpValue.setVerticalAlignment(Element.ALIGN_MIDDLE);
                details.addCell(sharpValue);

                PdfPCell itemNoValue = new PdfPCell(new Phrase(storageRecordDetail.getItemNo(), fontEN));
//                itemNoValue.setBorder(0);
                itemNoValue.setBorderWidthTop(0);
                itemNoValue.setBorderWidthLeft(0);
                itemNoValue.setBorderWidthBottom(0);
                itemNoValue.setBorderWidthRight(0);
                itemNoValue.setColspan(2);
                details.addCell(itemNoValue);

                PdfPCell projectNoValue = new PdfPCell(new Phrase(storageRecordDetail.getProjectNo(), fontEN));
//                projectNoValue.setBorder(0);
                projectNoValue.setBorderWidthTop(0);
                projectNoValue.setBorderWidthLeft(0);
                projectNoValue.setBorderWidthBottom(0);
                projectNoValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
                details.addCell(projectNoValue);

                PdfPCell arriveAmountValue = new PdfPCell(new Phrase("", fontEN));
//                arriveAmountValue.setBorder(0);
                arriveAmountValue.setBorderWidthTop(0);
                arriveAmountValue.setBorderWidthLeft(0);
                arriveAmountValue.setBorderWidthBottom(0);
                arriveAmountValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
                details.addCell(arriveAmountValue);

                PdfPCell priceAmountValue = new PdfPCell(new Phrase(storageRecordDetail.getPriceAmount().toString(), fontEN));
//                priceAmountValue.setBorder(0);
                priceAmountValue.setBorderWidthTop(0);
                priceAmountValue.setBorderWidthLeft(0);
                priceAmountValue.setBorderWidthBottom(0);
                priceAmountValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
                details.addCell(priceAmountValue);

                PdfPCell arriveAmountBackValue = new PdfPCell(new Phrase("", fontEN));
//                arriveAmountBackValue.setBorder(0);
                arriveAmountBackValue.setBorderWidthTop(0);
                arriveAmountBackValue.setBorderWidthLeft(0);
                arriveAmountBackValue.setBorderWidthBottom(0);
                arriveAmountBackValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
                details.addCell(arriveAmountBackValue);

                PdfPCell batchNoValue = new PdfPCell(new Phrase(storageRecordDetail.getBatchNo(), fontEN));
//              batchNoValue.setBorder(0);
                batchNoValue.setBorderWidthTop(0);
                batchNoValue.setBorderWidthBottom(0);
                batchNoValue.setBorderWidthLeft(0);
                details.addCell(batchNoValue);

                details.completeRow();
                //第一行结束
 
                PdfPCell itemDescribeValue = new PdfPCell(new Phrase(storageRecordDetail.getItemName(), fontCN));
//              itemDescribeValue.setBorder(0);
                itemDescribeValue.setBorderWidthTop(0);
                itemDescribeValue.setBorderWidthLeft(0);
                itemDescribeValue.setBorderWidthBottom(0);
                itemDescribeValue.setColspan(3);
                details.addCell(itemDescribeValue);


                PdfPCell itemAmountValue = new PdfPCell(new Phrase("", fontEN));
//                itemAmountValue.setBorder(0);
                itemAmountValue.setBorderWidthTop(0);
                itemAmountValue.setBorderWidthLeft(0);
                itemAmountValue.setBorderWidthBottom(0);
                itemAmountValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
                details.addCell(itemAmountValue);

                PdfPCell pieceQuantityValue = new PdfPCell(new Phrase(storageRecordDetail.getPieceQuantity().toString(), fontEN));
//                pieceQuantityValue.setBorder(0);
                pieceQuantityValue.setBorderWidthTop(0);
                pieceQuantityValue.setBorderWidthLeft(0);
                pieceQuantityValue.setBorderWidthBottom(0);
                pieceQuantityValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
                details.addCell(pieceQuantityValue);

              PdfPCell orderAmountOldsValue = new PdfPCell(new Phrase(storageRecordDetail.getOrderAmountOld().toString(), fontEN));
//              orderAmountOldsValue.setBorder(0);
              orderAmountOldsValue.setBorderWidthTop(0);
              orderAmountOldsValue.setBorderWidthLeft(0);
              orderAmountOldsValue.setBorderWidthBottom(0);
              orderAmountOldsValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
              details.addCell(orderAmountOldsValue);

              PdfPCell tbatchDescribeValue = new PdfPCell(new Phrase(storageRecordDetail.getBatchDescribe(), fontCN));
//              tbatchDescribeValue.setBorder(0);
              tbatchDescribeValue.setBorderWidthTop(0);
              tbatchDescribeValue.setBorderWidthLeft(0);
              tbatchDescribeValue.setBorderWidthBottom(0);
              tbatchDescribeValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
              details.addCell(tbatchDescribeValue);

              details.completeRow();
              //第二行结束

              PdfPCell itemPropertyValue = new PdfPCell(new Phrase(storageRecordDetail.getItemProperty(), fontCN));
//              itemPropertyValue.setBorder(0);
              itemPropertyValue.setBorderWidthTop(0);
              itemPropertyValue.setBorderWidthLeft(0);
              itemPropertyValue.setBorderWidthBottom(0);
              itemPropertyValue.setBorderWidthRight(0);
              itemPropertyValue.setColspan(2);
              details.addCell(itemPropertyValue);

              PdfPCell unitNameValue = new PdfPCell(new Phrase(storageRecordDetail.getUnitName(), fontCN));
//              unitNameValue.setBorder(0);
              unitNameValue.setBorderWidthTop(0);
              unitNameValue.setBorderWidthLeft(0);
              unitNameValue.setBorderWidthBottom(0);
              unitNameValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
              details.addCell(unitNameValue);

              String discountRates = storageRecordDetail.getDiscountRate().multiply(new BigDecimal(100)).toString() + "%";
              PdfPCell discountRateValue = new PdfPCell(new Phrase(discountRates, fontEN));
//              discountRateValue.setBorder(0);
              discountRateValue.setBorderWidthTop(0);
              discountRateValue.setBorderWidthLeft(0);
              discountRateValue.setBorderWidthBottom(0);
              discountRateValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
              details.addCell(discountRateValue);

              PdfPCell itemPriceValue = new PdfPCell(new Phrase(storageRecordDetail.getItemPrice().toString(), fontEN));
//              itemPriceValue.setBorder(0);
              itemPriceValue.setBorderWidthTop(0);
              itemPriceValue.setBorderWidthLeft(0);
              itemPriceValue.setBorderWidthBottom(0);
              itemPriceValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
              details.addCell(itemPriceValue);

              PdfPCell orderAmountTaxValue = new PdfPCell(new Phrase(storageRecordDetail.getOrderAmountTax().toString(), fontEN));
//              orderAmountTaxValue.setBorder(0);
              orderAmountTaxValue.setBorderWidthTop(0);
              orderAmountTaxValue.setBorderWidthLeft(0);
              orderAmountTaxValue.setBorderWidthBottom(0);
              orderAmountTaxValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
              details.addCell(orderAmountTaxValue);

              PdfPCell commentssValue = new PdfPCell(new Phrase(storageRecordDetail.getComments(), fontCN));
//              commentssValue.setBorder(0);
              commentssValue.setBorderWidthTop(0);
              commentssValue.setBorderWidthLeft(0);
              commentssValue.setRowspan(2);
              details.addCell(commentssValue);

              details.completeRow();
              //第三行结束
              

              PdfPCell floorNoValue = new PdfPCell(new Phrase(storageRecordDetail.getFloorNo(), fontCN));
//              floorNoValue.setBorder(0);
              floorNoValue.setBorderWidthTop(0);
              floorNoValue.setBorderWidthLeft(0);
              floorNoValue.setBorderWidthRight(0);
              floorNoValue.setColspan(2);
              details.addCell(floorNoValue);

              PdfPCell storageNoValue = new PdfPCell(new Phrase(storageRecordDetail.getStorageNo(), fontEN));
//              storageNoValue.setBorder(0);
              storageNoValue.setBorderWidthTop(0);
              storageNoValue.setBorderWidthLeft(0);
              storageNoValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
              details.addCell(storageNoValue);

              PdfPCell taxRatesValue = new PdfPCell(new Phrase(storageRecordDetail.getTaxRate().toString(), fontEN));
//              taxRatesValue.setBorder(0);
              taxRatesValue.setBorderWidthTop(0);
              taxRatesValue.setBorderWidthLeft(0);
              taxRatesValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
              details.addCell(taxRatesValue);

              PdfPCell orderAmountValue = new PdfPCell(new Phrase(storageRecordDetail.getOrderAmount().toString(), fontEN));
//              orderAmountValue.setBorder(0);
              orderAmountValue.setBorderWidthTop(0);
              orderAmountValue.setBorderWidthLeft(0);
              orderAmountValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
              details.addCell(orderAmountValue);

              PdfPCell orderAmountTotalValue = new PdfPCell(new Phrase(storageRecordDetail.getOrderAmountTotal().toString(), fontEN));
//              orderAmountTotalValue.setBorder(0);
              orderAmountTotalValue.setBorderWidthTop(0);
              orderAmountTotalValue.setBorderWidthLeft(0);
              orderAmountTotalValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
              details.addCell(orderAmountTotalValue);

              details.completeRow();
              //第四行结束
              
            }
            
            doc.add(details);
      	
        }
        ////////////////////////////////////////////////////////////////////////////////////////////
        
//	    doc.add(line);

	    
        PdfPTable masterFoot = new PdfPTable(8);
        
        masterFoot.setTotalWidth(new float[]{45, 85, 45, 85, 45, 85, 45, 85});
        masterFoot.setLockedWidth(true);
//        masterFoot.setSpacingBefore(10);

        PdfPCell detailsCountCell = new PdfPCell(new Phrase("笔数:", fontCN));
//        detailsCountCell.setBorder(0);
        detailsCountCell.setBorderWidthTop(0);
        detailsCountCell.setBorderWidthBottom(0);
        detailsCountCell.setBorderWidthRight(0);
        masterFoot.addCell(detailsCountCell);

        PdfPCell detailsCountValue = new PdfPCell(new Phrase(String.valueOf(storageRecord.getDetailsCount()), fontEN));
        detailsCountValue.setBorder(0);
        masterFoot.addCell(detailsCountValue);

        PdfPCell r1emptyCell = new PdfPCell(new Phrase(""));
//        r1emptyCell.setBorder(0);
        r1emptyCell.setBorderWidthTop(0);
        r1emptyCell.setBorderWidthBottom(0);
        r1emptyCell.setBorderWidthLeft(0);
        r1emptyCell.setColspan(6);
        masterFoot.addCell(r1emptyCell);

        //第一行结束
        masterFoot.completeRow();

        PdfPCell itemAmountCell = new PdfPCell(new Phrase("数量合计:", fontCN));
//        itemAmountCell.setBorder(0);
        itemAmountCell.setBorderWidthTop(0);
        itemAmountCell.setBorderWidthRight(0);
        masterFoot.addCell(itemAmountCell);

        PdfPCell itemAmountValue = new PdfPCell(new Phrase(storageRecord.getItemAmount().toString(), fontEN));
        itemAmountValue.setBorderWidthTop(0);
        itemAmountValue.setBorderWidthLeft(0);
        itemAmountValue.setBorderWidthRight(0);
        masterFoot.addCell(itemAmountValue);

        PdfPCell orderAmountOldCell = new PdfPCell(new Phrase("未税金额:", fontCN));
        orderAmountOldCell.setBorderWidthTop(0);
        orderAmountOldCell.setBorderWidthLeft(0);
        orderAmountOldCell.setBorderWidthRight(0);
        masterFoot.addCell(orderAmountOldCell);

        PdfPCell orderAmountOldValue = new PdfPCell(new Phrase(storageRecord.getOrderAmountOld().toString(), fontEN));
        orderAmountOldValue.setBorderWidthTop(0);
        orderAmountOldValue.setBorderWidthLeft(0);
        orderAmountOldValue.setBorderWidthRight(0);
        masterFoot.addCell(orderAmountOldValue);

        PdfPCell orderAmountTaxCell = new PdfPCell(new Phrase("税额:", fontCN));
        orderAmountTaxCell.setBorderWidthTop(0);
        orderAmountTaxCell.setBorderWidthLeft(0);
        orderAmountTaxCell.setBorderWidthRight(0);
        masterFoot.addCell(orderAmountTaxCell);

        PdfPCell orderAmountTaxValue = new PdfPCell(new Phrase(storageRecord.getOrderAmountTax().toString(), fontEN));
        orderAmountTaxValue.setBorderWidthTop(0);
        orderAmountTaxValue.setBorderWidthLeft(0);
        orderAmountTaxValue.setBorderWidthRight(0);
        masterFoot.addCell(orderAmountTaxValue);

        PdfPCell orderAmountTotalCell = new PdfPCell(new Phrase("价税合计:", fontCN));
        orderAmountTotalCell.setBorderWidthTop(0);
        orderAmountTotalCell.setBorderWidthLeft(0);
        orderAmountTotalCell.setBorderWidthRight(0);
        masterFoot.addCell(orderAmountTotalCell);

        PdfPCell orderAmountTotalValue = new PdfPCell(new Phrase(storageRecord.getOrderAmountTotal().toString(), fontEN));
//        orderAmountTotalValue.setBorder(0);
        orderAmountTotalValue.setBorderWidthTop(0);
        orderAmountTotalValue.setBorderWidthLeft(0);
        masterFoot.addCell(orderAmountTotalValue);

        //第二行结束
        masterFoot.completeRow();


        doc.add(masterFoot);
        
        
        
	    
        PdfPTable masterTail = new PdfPTable(8);
        
        masterTail.setTotalWidth(new float[]{45, 65, 45, 105, 45, 65, 45, 105});
        masterTail.setLockedWidth(true);
        masterTail.setSpacingBefore(10);

        PdfPCell cUsernameCell = new PdfPCell(new Phrase("制单:", fontCN));
        cUsernameCell.setBorder(0);
        masterTail.addCell(cUsernameCell);

        PdfPCell cUsernameValue = new PdfPCell(new Phrase(storageRecord.getcUsername(), fontCN));
        cUsernameValue.setBorder(0);
        masterTail.addCell(cUsernameValue);

        PdfPCell cDatetimeCell = new PdfPCell(new Phrase("制单时间:", fontCN));
        cDatetimeCell.setBorder(0);
        masterTail.addCell(cDatetimeCell);

        PdfPCell cDatetimeValue = new PdfPCell(new Phrase(storageRecord.getcDatetime().toString(), fontEN));
        cDatetimeValue.setBorder(0);
        masterTail.addCell(cDatetimeValue);

        PdfPCell tUsernameCell = new PdfPCell(new Phrase("审核:", fontCN));
        tUsernameCell.setBorder(0);
        masterTail.addCell(tUsernameCell);

        PdfPCell tUsernameValue = new PdfPCell(new Phrase(storageRecord.gettUsername(), fontCN));
        tUsernameValue.setBorder(0);
        masterTail.addCell(tUsernameValue);

        PdfPCell tDatetimeCell = new PdfPCell(new Phrase("审核时间:", fontCN));
        tDatetimeCell.setBorder(0);
        masterTail.addCell(tDatetimeCell);

        PdfPCell tDatetimeValue = new PdfPCell(new Phrase(storageRecord.gettDatetime()==null?"":storageRecord.gettDatetime().toString(), fontEN));
        tDatetimeValue.setBorder(0);
        masterTail.addCell(tDatetimeValue);


        masterTail.completeRow();
        

        doc.add(masterTail);
	    
        Chunk printTimeChunk = new Chunk("打印时间: ",fontCN);
        String printTime = Utils.getCurrentDateTime().toString();
        Paragraph printTimeParagraph = new Paragraph(printTimeChunk);
        Chunk printTimeValueChunk = new Chunk(printTime,fontEN);
        printTimeParagraph.add(printTimeValueChunk);
        printTimeParagraph.setAlignment(Element.ALIGN_RIGHT);
	    doc.add(printTimeParagraph);

	    
//	    doc.close();
	    
	    
	    
//        int pageNumber = doc.getPageNumber();
//        System.out.println(pageNumber);
//	    Rectangle rect = doc.getPageSize();
//	    System.out.println("rect.getHeight()-->"+rect.getHeight());
//	    System.out.println("rect.getWidth()-->"+rect.getWidth());
//	    System.out.println("rect.getLeft()-->"+rect.getLeft());
//	    System.out.println("rect.getTop()-->"+rect.getTop());
//	    System.out.println("rect.getBottom()-->"+rect.getBottom());
//	    System.out.println("rect.getRight()-->"+rect.getRight());
//	    System.out.println("rect.getBorder()-->"+rect.getBorder());
//	    System.out.println("rect.getBorderWidth()-->"+rect.getBorderWidth());
//	    System.out.println("rect.getBorderWidthTop()-->"+rect.getBorderWidthTop());
//	    System.out.println("rect.getBorderWidthLeft()-->"+rect.getBorderWidthLeft());
//	    System.out.println("rect.getBorderWidthBottom()-->"+rect.getBorderWidthBottom());
//	    System.out.println("rect.getBorderWidthRight()-->"+rect.getBorderWidthRight());

	}

		@Override
		public void invXSRKPrintPDF(String fID, Document doc) throws Exception {
			
	//	@Test
	//	public void storageRecordPrintPDF() throws Exception {
	//		System.out.println("fID-->"+id);
			
	//	    Document doc = new Document();// 创建一个PDF文档，我们的PDF内容都写在上面
		    
	//	    PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(new File("c://pdftest//storageRecord.pdf"))); // 将pdf文档写入文件
	
	//		String fID = "bf61ec2bc8163a3ad3d8572ad2fee7c6";
			StorageRecord storageRecord = storageRecordService.getByID(fID);
		   
	//	    response.setContentType("application/pdf");
	//	    PdfWriter.getInstance(doc, response.getOutputStream());
	//	    
	//	    doc.open();
		    
		    Font fontEN = new Font(BaseFont.createFont(),9);
		    BaseFont baseFont = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);  	    
	//	    Font font = new Font(baseFont, 10, Font.ITALIC);
		    Font fontCN = new Font(baseFont, 9);
		    Paragraph pEnterpriseName = new Paragraph(storageRecord.getEnterpriseName(),fontCN);
		    // 居中显示
		    pEnterpriseName.setAlignment(Element.ALIGN_CENTER);
		    pEnterpriseName.setSpacingAfter(-10);
		    Paragraph pBillTypeName = new Paragraph(storageRecord.getBillTypeName(),new Font(baseFont,20));
		    // 居中显示
		    pBillTypeName.setAlignment(Element.ALIGN_CENTER);
		    LineSeparator line = new LineSeparator(1f, 100, BaseColor.BLACK, Element.ALIGN_CENTER, -5f);
	
		    
		    
		    
		    
		    
		    doc.add(pEnterpriseName);
		    doc.add(pBillTypeName);
		    doc.add(line);
		    
		    
	        PdfPTable masterHead = new PdfPTable(8);
	        
	//        masterHead.setTotalWidth(new float[]{60, 200, 60, 200});
	        masterHead.setTotalWidth(new float[]{45, 85, 45, 85, 45, 85, 45, 85});
	        masterHead.setLockedWidth(true);
	        masterHead.setSpacingBefore(10);
	        
	        PdfPCell ordrDateCell = new PdfPCell(new Phrase("单据日期:", fontCN));
	        ordrDateCell.setUseBorderPadding(true);
	        //
	        // Setting cell's border width and color
	        //
	        ordrDateCell.setBorderWidth(0f);
	//        ordrDateCell.setBorderColor(BaseColor.BLUE);
	        masterHead.addCell(ordrDateCell);
	
	        PdfPCell ordrDateValue = new PdfPCell(new Phrase(storageRecord.getOrderDate().toString(), fontEN));
	        ordrDateValue.setUseBorderPadding(true);
	        ordrDateValue.setBorderWidth(0f);
	        //
	        // Setting cell's background color
	        //
	//        cell2.setBackgroundColor(BaseColor.GRAY);
	        //
	        // Setting cell's individual border color
	        //
	//        cell2.setBorderWidthTop(1f);
	//        cell2.setBorderColorTop(BaseColor.RED);
	//        cell2.setBorderColorRight(BaseColor.GREEN);
	//        cell2.setBorderColorBottom(BaseColor.BLUE);
	//        cell2.setBorderColorLeft(BaseColor.BLACK);
	        masterHead.addCell(ordrDateValue);
	
	        PdfPCell auditCell = new PdfPCell(new Phrase("单据状态:", fontCN));
	        auditCell.setUseBorderPadding(true);
	        auditCell.setBorderWidth(0f);
	        //
	        // Setting cell's individual border width
	        //
	//        cell3.setBorderWidthTop(2f);
	//        cell3.setBorderWidthRight(1f);
	//        cell3.setBorderWidthBottom(2f);
	//        cell3.setBorderWidthLeft(1f);
	        masterHead.addCell(auditCell);
	
	        String auditStatus = "待审核";
	        String audit = storageRecord.getAudit();
	        String state = storageRecord.getState();
	        if(audit.equals("confirm")){
	        	auditStatus = "已审核";
	        }else if(audit.equals("active") && state.equals("confirm")){
	        	auditStatus = "审核中";
	        }else{
	        	auditStatus = "待审核";
	        }
	        
	       PdfPCell auditValue = new PdfPCell(new Phrase(auditStatus, fontCN));
	       auditValue.setUseBorderPadding(true);
	       auditValue.setBorderWidth(0f);
	        //
	        // Setting cell's individual border width
	        //
	//        cell4.setBorderWidthTop(2f);
	//        cell4.setBorderWidthRight(1f);
	//        cell4.setBorderWidthBottom(2f);
	//        cell4.setBorderWidthLeft(1f);
	        masterHead.addCell(auditValue);
	        
	        String providerNoLabel = "";
	        String shortNameLabel = "";
	        String providerNameLabel = "";
	        
	        if(storageRecord.getBillType().equals("CGRK") || storageRecord.getBillType().equals("WWRK")){
	            
	            providerNoLabel = "供方编码:";
	            shortNameLabel = "供方简称:";
	            providerNameLabel = "供方名称:";
	        	
	        }
	        
	        if(storageRecord.getBillType().equals("XSRK")){
	            
	            providerNoLabel = "客户编码:";
	            shortNameLabel = "客户简称:";
	            providerNameLabel = "客户名称:";
	        	
	        }
	        
	        PdfPCell providerNoCell = new PdfPCell(new Phrase(providerNoLabel, fontCN));
	        providerNoCell.setBorder(0);
	        masterHead.addCell(providerNoCell);
	        PdfPCell providerNoValue = new PdfPCell(new Phrase(storageRecord.getProviderNo(), fontEN));
	        providerNoValue.setBorder(0);
	        masterHead.addCell(providerNoValue);
	        
	        PdfPCell shortNameCell = new PdfPCell(new Phrase(shortNameLabel, fontCN));
	        shortNameCell.setBorder(0);
	        masterHead.addCell(shortNameCell);
	        PdfPCell shortNameValue = new PdfPCell(new Phrase(storageRecord.getShortName(), fontCN));
	        shortNameValue.setBorder(0);
	        masterHead.addCell(shortNameValue);
	
	        //第一行结束
	        masterHead.completeRow();
	        
	        PdfPCell orderNoCell = new PdfPCell(new PdfPCell(new Phrase("单号:", fontCN)));
	        orderNoCell.setBorder(0);
	        masterHead.addCell(orderNoCell);
	        PdfPCell orderNoValue = new PdfPCell(new PdfPCell(new Phrase(storageRecord.getRecordNo(), fontEN)));
	        orderNoValue.setBorder(0);
	        orderNoValue.setColspan(3);
	        masterHead.addCell(orderNoValue);
	        
	        PdfPCell providerNameCell = new PdfPCell(new Phrase(providerNameLabel, fontCN));
	        providerNameCell.setBorder(0);
	        masterHead.addCell(providerNameCell);
	        PdfPCell providerNameValue = new PdfPCell(new Phrase(storageRecord.getProviderName(), fontCN));
	        providerNameValue.setBorder(0);
	        providerNameValue.setColspan(3);
	        masterHead.addCell(providerNameValue);
	        //第二行结束
	        masterHead.completeRow();
	        
	        PdfPCell factoryNoCell = new PdfPCell(new PdfPCell(new Phrase("工厂编码:", fontCN)));
	        factoryNoCell.setBorder(0);
	        masterHead.addCell(factoryNoCell);
	        PdfPCell factoryNoValue = new PdfPCell(new PdfPCell(new Phrase(storageRecord.getFactoryNo(), fontEN)));
	        factoryNoValue.setBorder(0);
	        masterHead.addCell(factoryNoValue);
	        
	        PdfPCell factoryNameCell = new PdfPCell(new PdfPCell(new Phrase("工厂名称:", fontCN)));
	        factoryNameCell.setBorder(0);
	        masterHead.addCell(factoryNameCell);
	        PdfPCell factoryNameValue = new PdfPCell(new PdfPCell(new Phrase(storageRecord.getFactoryName(), fontCN)));
	        factoryNameValue.setBorder(0);
	        masterHead.addCell(factoryNameValue);
	        
	        PdfPCell invoiceCategoryLabelCell = new PdfPCell(new PdfPCell(new Phrase("发票类型:", fontCN)));
	        invoiceCategoryLabelCell.setBorder(0);
	        masterHead.addCell(invoiceCategoryLabelCell);
	        PdfPCell invoiceCategoryLabelValue = new PdfPCell(new PdfPCell(new Phrase(storageRecord.getInvoiceCategoryLabel(), fontCN)));
	        invoiceCategoryLabelValue.setBorder(0);
	        masterHead.addCell(invoiceCategoryLabelValue);
	        
	        PdfPCell settleCategoryLabelCell = new PdfPCell(new Phrase("结算方式:", fontCN));
	        settleCategoryLabelCell.setBorder(0);
	        masterHead.addCell(settleCategoryLabelCell);
	        PdfPCell settleCategoryLabelValue = new PdfPCell(new Phrase(storageRecord.getSettleCategoryLabel(), fontCN));
	        settleCategoryLabelValue.setBorder(0);
	        masterHead.addCell(settleCategoryLabelValue);
	        //第三行结束
	        masterHead.completeRow();
	        
	        PdfPCell taxTypeLabelCell = new PdfPCell(new PdfPCell(new Phrase("税种:", fontCN)));
	        taxTypeLabelCell.setBorder(0);
	        masterHead.addCell(taxTypeLabelCell);
	        PdfPCell taxTypeLabelValue = new PdfPCell(new PdfPCell(new Phrase(storageRecord.getTaxTypeLabel(), fontCN)));
	        taxTypeLabelValue.setBorder(0);
	        masterHead.addCell(taxTypeLabelValue);
	        
	        PdfPCell taxRateCell = new PdfPCell(new PdfPCell(new Phrase("税率:", fontCN)));
	        taxRateCell.setBorder(0);
	        masterHead.addCell(taxRateCell);
	        PdfPCell taxRateValue = new PdfPCell(new PdfPCell(new Phrase(storageRecord.getTaxRate().toString(), fontEN)));
	        taxRateValue.setBorder(0);
	        masterHead.addCell(taxRateValue);
	        
	        PdfPCell fAddressCell = new PdfPCell(new Phrase("地址:", fontCN));
	        fAddressCell.setBorder(0);
	        masterHead.addCell(fAddressCell);
	        PdfPCell fAddressValue = new PdfPCell(new Phrase(storageRecord.getfAddress(), fontCN));
	        fAddressValue.setBorder(0);
	        fAddressValue.setColspan(3);
	        masterHead.addCell(fAddressValue);
	        //第四行结束
	        masterHead.completeRow();
	        
	        PdfPCell employeeNameCell = new PdfPCell(new Phrase("经办人:", fontCN));
	        employeeNameCell.setBorder(0);
	        masterHead.addCell(employeeNameCell);
	        PdfPCell employeeNameValue = new PdfPCell(new Phrase(storageRecord.getEmployeeName(), fontCN));
	        employeeNameValue.setBorder(0);
	        employeeNameValue.setColspan(3);
	        masterHead.addCell(employeeNameValue);
	        
	        PdfPCell fAddressDetailCell = new PdfPCell(new Phrase("详细地址:", fontCN));
	        fAddressDetailCell.setBorder(0);
	        masterHead.addCell(fAddressDetailCell);
	        PdfPCell fAddressDetailValue = new PdfPCell(new Phrase(storageRecord.getfAddressDetail(), fontCN));
	        fAddressDetailValue.setBorder(0);
	        fAddressDetailValue.setColspan(3);
	        masterHead.addCell(fAddressDetailValue);
	        //第五行结束
	        masterHead.completeRow();
	        
	        PdfPCell shipperNameCell = new PdfPCell(new PdfPCell(new Phrase("物流公司:", fontCN)));
	        shipperNameCell.setBorder(0);
	        masterHead.addCell(shipperNameCell);
	        PdfPCell shipperNameValue = new PdfPCell(new PdfPCell(new Phrase(storageRecord.getContacts(), fontCN)));
	        shipperNameValue.setBorder(0);
	        masterHead.addCell(shipperNameValue);
	        
	        PdfPCell waybillNoCell = new PdfPCell(new PdfPCell(new Phrase("运单号:", fontCN)));
	        waybillNoCell.setBorder(0);
	        masterHead.addCell(waybillNoCell);
	        PdfPCell waybillNoValue = new PdfPCell(new PdfPCell(new Phrase(storageRecord.getContacts(), fontEN)));
	        waybillNoValue.setBorder(0);
	        masterHead.addCell(waybillNoValue);
	        
	        PdfPCell contactsCell = new PdfPCell(new Phrase("联系人:", fontCN));
	        contactsCell.setBorder(0);
	        masterHead.addCell(contactsCell);
	        PdfPCell contactsValue = new PdfPCell(new Phrase(storageRecord.getContacts(), fontCN));
	        contactsValue.setBorder(0);
	        masterHead.addCell(contactsValue);
	        
	        PdfPCell mobilePhoneCell = new PdfPCell(new Phrase("联系电话:", fontCN));
	        mobilePhoneCell.setBorder(0);
	        masterHead.addCell(mobilePhoneCell);
	        PdfPCell mobilePhoneValue = new PdfPCell(new Phrase(storageRecord.getMobilePhone(), fontEN));
	        mobilePhoneValue.setBorder(0);
	        masterHead.addCell(mobilePhoneValue);
	        //第六行结束
	        masterHead.completeRow();
	        
	        PdfPCell paymentTermLabelCell = new PdfPCell(new Phrase("付款条件:", fontCN));
	        paymentTermLabelCell.setBorder(0);
	        masterHead.addCell(paymentTermLabelCell);
	        PdfPCell paymentTermLabelValue = new PdfPCell(new Phrase(storageRecord.getPaymentTermLabel(), fontCN));
	        paymentTermLabelValue.setBorder(0);
	        paymentTermLabelValue.setColspan(7);
	        masterHead.addCell(paymentTermLabelValue);
	        //第七行结束
	        masterHead.completeRow();
	        
	        PdfPCell commentsCell = new PdfPCell(new Phrase("备注:", fontCN));
	        commentsCell.setBorder(0);
	        masterHead.addCell(commentsCell);
	        PdfPCell commentsValue = new PdfPCell(new Phrase(storageRecord.getComments(), fontCN));
	        commentsValue.setBorder(0);
	        commentsValue.setColspan(7);
	        masterHead.addCell(commentsValue);
	        
	        //第n行结束
	        masterHead.completeRow();
	
	        doc.add(masterHead);
	//	    doc.add(line);
		    
	
	        /*
	        Image image = Image.getInstance("c://pdftest//smp.png");
	
	        image.setAlignment(Image.ALIGN_RIGHT);
	        // 设置边框
	        image.setBorder(Image.BOX);
	        image.setBorderWidth(2);
	        image.setBorderColor(BaseColor.RED);
	        // 设置图片大小
	        
	//        ScaleToFit有两个参数，指的是长和宽的最大值，但是图片的长宽比还是不会变的
	//        ScaleAbsoluteHeight设置图片的高度，不管长宽比 ScaleAbsoluteWidth设置图片的宽度，不管长宽比
	//        ScalePercent等比例缩放
	        
	//         image.scaleToFit(100, 100);
	//         image.scaleAbsoluteHeight(100f);
	//         image.scaleAbsoluteWidth(100f);
	
	        image.scalePercent(50f);
	        // 图片旋转30度
	        image.setRotationDegrees(30);
	
	        doc.add(image);
	        */
	        
	        
	        
	        
	        
		    //////////////////////////////////////////////////////////////////////////////////////////
		    
	        PdfPTable details = new PdfPTable(8);
	        details.setTotalWidth(new float[]{15, 70, 70, 80, 65, 75, 65, 80});//520
	        details.setLockedWidth(true);
	        details.setSpacingBefore(10);
	
	        PdfPCell sharpCell = new PdfPCell(new Phrase("序号", fontCN));
	//        sharpCell.setBorder(0);
	        sharpCell.setRowspan(4);
	        sharpCell.setHorizontalAlignment(Element.ALIGN_CENTER);
	        sharpCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
	        details.addCell(sharpCell);
	
	        PdfPCell itemNoCell = new PdfPCell(new Phrase("物料编码", fontCN));
	//        itemNoCell.setBorder(0);
	//        itemNoCell.setBorderWidthTop(0);
	        itemNoCell.setBorderWidthLeft(0);
	        itemNoCell.setBorderWidthBottom(0);
	        itemNoCell.setBorderWidthRight(0);
	        itemNoCell.setColspan(2);
	        details.addCell(itemNoCell);
	
	        PdfPCell projectNoCell = new PdfPCell(new Phrase("项目号", fontCN));
	//        projectNoCell.setBorder(0);
	        projectNoCell.setBorderWidthLeft(0);
	        projectNoCell.setBorderWidthBottom(0);
	        projectNoCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
	        details.addCell(projectNoCell);
	
	        PdfPCell arriveAmountsCell = new PdfPCell(new Phrase("到货数量", fontCN));
	//        arriveAmountsCell.setBorder(0);
	        arriveAmountsCell.setBorderWidthLeft(0);
	        arriveAmountsCell.setBorderWidthBottom(0);
	        arriveAmountsCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
	        details.addCell(arriveAmountsCell);
	
	        PdfPCell priceAmountCell = new PdfPCell(new Phrase("计价数量", fontCN));
	//        priceAmountCell.setBorder(0);
	        priceAmountCell.setBorderWidthLeft(0);
	        priceAmountCell.setBorderWidthBottom(0);
	        priceAmountCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
	        details.addCell(priceAmountCell);
	
	        PdfPCell arriveAmountBackCell = new PdfPCell(new Phrase("验退数量", fontCN));
	//        arriveAmountBackCell.setBorder(0);
	        arriveAmountBackCell.setBorderWidthLeft(0);
	        arriveAmountBackCell.setBorderWidthBottom(0);
	        arriveAmountBackCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
	        details.addCell(arriveAmountBackCell);
	
	        PdfPCell batchNoCell = new PdfPCell(new Phrase("批号", fontCN));
	//        batchNoCell.setBorder(0);
	        batchNoCell.setBorderWidthLeft(0);
	        batchNoCell.setBorderWidthBottom(0);
	        details.addCell(batchNoCell);
	        
	        details.completeRow();
	        //第一行结束
	
	        PdfPCell itemDescribeCell = new PdfPCell(new Phrase("名称", fontCN));
	//        itemDescribeCell.setBorder(0);
	        itemDescribeCell.setBorderWidthTop(0);
	        itemDescribeCell.setBorderWidthLeft(0);
	        itemDescribeCell.setBorderWidthBottom(0);
	        itemDescribeCell.setColspan(3);
	        details.addCell(itemDescribeCell);
	
	        PdfPCell itemAmountsCell = new PdfPCell(new Phrase("合格数量", fontCN));
	//        itemAmountsCell.setBorder(0);
	        itemAmountsCell.setBorderWidthTop(0);
	        itemAmountsCell.setBorderWidthLeft(0);
	        itemAmountsCell.setBorderWidthBottom(0);
	        itemAmountsCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
	        details.addCell(itemAmountsCell);
	
	        PdfPCell pieceQuantityCell = new PdfPCell(new Phrase("件数", fontCN));
	//        pieceQuantityCell.setBorder(0);
	        pieceQuantityCell.setBorderWidthTop(0);
	        pieceQuantityCell.setBorderWidthLeft(0);
	        pieceQuantityCell.setBorderWidthBottom(0);
	        pieceQuantityCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
	        details.addCell(pieceQuantityCell);
	
	        PdfPCell orderAmountOldsCell = new PdfPCell(new Phrase("未税金额", fontCN));
	//        orderAmountOldsCell.setBorder(0);
	        orderAmountOldsCell.setBorderWidthTop(0);
	        orderAmountOldsCell.setBorderWidthLeft(0);
	        orderAmountOldsCell.setBorderWidthBottom(0);
	        orderAmountOldsCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
	        details.addCell(orderAmountOldsCell);
	
	        PdfPCell batchDescribeCell = new PdfPCell(new Phrase("批号说明", fontCN));
	//        batchDescribeCell.setBorder(0);
	        batchDescribeCell.setBorderWidthTop(0);
	        batchDescribeCell.setBorderWidthLeft(0);
	        batchDescribeCell.setBorderWidthBottom(0);
	        details.addCell(batchDescribeCell);
	
	        details.completeRow();
	        //第二行结束
	
	        PdfPCell itemPropertyCell = new PdfPCell(new Phrase("规格", fontCN));
	//        itemPropertyCell.setBorder(0);
	        itemPropertyCell.setBorderWidthTop(0);
	        itemPropertyCell.setBorderWidthLeft(0);
	        itemPropertyCell.setBorderWidthBottom(0);
	        itemPropertyCell.setBorderWidthRight(0);
	        itemPropertyCell.setColspan(2);
	        details.addCell(itemPropertyCell);
	
	        PdfPCell unitNameCell = new PdfPCell(new Phrase("单位", fontCN));
	//        unitNameCell.setBorder(0);
	        unitNameCell.setBorderWidthTop(0);
	        unitNameCell.setBorderWidthLeft(0);
	        unitNameCell.setBorderWidthBottom(0);
	        unitNameCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
	        details.addCell(unitNameCell);
	
	        PdfPCell ullageAmountCell = new PdfPCell(new Phrase("损耗数量", fontCN));
	//        ullageAmountCell.setBorder(0);
	        ullageAmountCell.setBorderWidthTop(0);
	        ullageAmountCell.setBorderWidthLeft(0);
	        ullageAmountCell.setBorderWidthBottom(0);
	        ullageAmountCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
	        details.addCell(ullageAmountCell);
	
	        PdfPCell itemPriceCell = new PdfPCell(new Phrase("单价", fontCN));
	//        itemPriceCell.setBorder(0);
	        itemPriceCell.setBorderWidthTop(0);
	        itemPriceCell.setBorderWidthLeft(0);
	        itemPriceCell.setBorderWidthBottom(0);
	        itemPriceCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
	        details.addCell(itemPriceCell);
	
	        PdfPCell orderAmountTaxsCell = new PdfPCell(new Phrase("税额", fontCN));
	//        orderAmountTaxsCell.setBorder(0);
	        orderAmountTaxsCell.setBorderWidthTop(0);
	        orderAmountTaxsCell.setBorderWidthLeft(0);
	        orderAmountTaxsCell.setBorderWidthBottom(0);
	        orderAmountTaxsCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
	        details.addCell(orderAmountTaxsCell);
	
	        PdfPCell commentssCell = new PdfPCell(new Phrase("备注", fontCN));
	//        commentssCell.setBorder(0);
	        commentssCell.setBorderWidthTop(0);
	        commentssCell.setBorderWidthLeft(0);
	        commentssCell.setRowspan(2);
	        details.addCell(commentssCell);
	
	        details.completeRow();
	        //第三行结束
	
	        PdfPCell floorNoCell = new PdfPCell(new Phrase("库存地", fontCN));
	//        floorNoCell.setBorder(0);
	        floorNoCell.setBorderWidthTop(0);
	        floorNoCell.setBorderWidthLeft(0);
	        floorNoCell.setBorderWidthRight(0);
	        floorNoCell.setColspan(2);
	        details.addCell(floorNoCell);
	
	        PdfPCell storageNoCell = new PdfPCell(new Phrase("仓库编码", fontCN));
	//        storageNoCell.setBorder(0);
	        storageNoCell.setBorderWidthTop(0);
	        storageNoCell.setBorderWidthLeft(0);
	        storageNoCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
	        details.addCell(storageNoCell);
	
	        PdfPCell wasterAmountCell = new PdfPCell(new Phrase("报废数量", fontCN));
	//        wasterAmountCell.setBorder(0);
	        wasterAmountCell.setBorderWidthTop(0);
	        wasterAmountCell.setBorderWidthLeft(0);
	        wasterAmountCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
	        details.addCell(wasterAmountCell);
	
	        PdfPCell orderAmountCell = new PdfPCell(new Phrase("金额", fontCN));
	//        orderAmountCell.setBorder(0);
	        orderAmountCell.setBorderWidthTop(0);
	        orderAmountCell.setBorderWidthLeft(0);
	        orderAmountCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
	        details.addCell(orderAmountCell);
	
	        PdfPCell orderAmountTotalsCell = new PdfPCell(new Phrase("价税合计", fontCN));
	//        orderAmountTotalsCell.setBorder(0);
	        orderAmountTotalsCell.setBorderWidthTop(0);
	        orderAmountTotalsCell.setBorderWidthLeft(0);
	        orderAmountTotalsCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
	        details.addCell(orderAmountTotalsCell);
	
	        details.completeRow();
	        //第四行结束
	        
	        
	//        doc.add(details);
	        
	        ////////////////////////////////////////////////////////////////////////////////////////////
	        
	        
		    //////////////////////////////////////////////////////////////////////////////////////////
	        List<StorageRecordDetail> storageRecordDetails = storageRecordDetailService.getByMasterID(fID);
	        if(storageRecordDetails.size()>0){
	    	    
	//            PdfPTable detailsValue = new PdfPTable(8);
	//            
	//            detailsValue.setTotalWidth(new float[]{20, 70, 70, 80, 80, 80, 60, 60});//520
	//            detailsValue.setLockedWidth(true);
	//            detailsValue.setSpacingBefore(10);
	            
	            for(int i=0;i<storageRecordDetails.size();i++){
	            	StorageRecordDetail storageRecordDetail = storageRecordDetails.get(i);
	
	            	//序号
	            	String rowNo = String.valueOf(i+1);
	                PdfPCell sharpValue = new PdfPCell(new Phrase(rowNo, fontEN));
	//                sharpValue.setBorder(0);
	                sharpValue.setBorderWidthTop(0);
	                sharpValue.setRowspan(4);
	                sharpValue.setHorizontalAlignment(Element.ALIGN_CENTER);
	                sharpValue.setVerticalAlignment(Element.ALIGN_MIDDLE);
	                details.addCell(sharpValue);
	
	                PdfPCell itemNoValue = new PdfPCell(new Phrase(storageRecordDetail.getItemNo(), fontEN));
	//                itemNoValue.setBorder(0);
	                itemNoValue.setBorderWidthTop(0);
	                itemNoValue.setBorderWidthLeft(0);
	                itemNoValue.setBorderWidthBottom(0);
	                itemNoValue.setBorderWidthRight(0);
	                itemNoValue.setColspan(2);
	                details.addCell(itemNoValue);
	
	                PdfPCell projectNoValue = new PdfPCell(new Phrase(storageRecordDetail.getProjectNo(), fontEN));
	//                projectNoValue.setBorder(0);
	                projectNoValue.setBorderWidthTop(0);
	                projectNoValue.setBorderWidthLeft(0);
	                projectNoValue.setBorderWidthBottom(0);
	                projectNoValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
	                details.addCell(projectNoValue);
	
	                PdfPCell arriveAmountValue = new PdfPCell(new Phrase(storageRecordDetail.getArriveAmount().toString(), fontEN));
	//                arriveAmountValue.setBorder(0);
	                arriveAmountValue.setBorderWidthTop(0);
	                arriveAmountValue.setBorderWidthLeft(0);
	                arriveAmountValue.setBorderWidthBottom(0);
	                arriveAmountValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
	                details.addCell(arriveAmountValue);
	
	                PdfPCell priceAmountValue = new PdfPCell(new Phrase(storageRecordDetail.getPriceAmount().toString(), fontEN));
	//                priceAmountValue.setBorder(0);
	                priceAmountValue.setBorderWidthTop(0);
	                priceAmountValue.setBorderWidthLeft(0);
	                priceAmountValue.setBorderWidthBottom(0);
	                priceAmountValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
	                details.addCell(priceAmountValue);
	
	                PdfPCell arriveAmountBackValue = new PdfPCell(new Phrase(storageRecordDetail.getArriveAmountBack().toString(), fontEN));
	//                arriveAmountBackValue.setBorder(0);
	                arriveAmountBackValue.setBorderWidthTop(0);
	                arriveAmountBackValue.setBorderWidthLeft(0);
	                arriveAmountBackValue.setBorderWidthBottom(0);
	                arriveAmountBackValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
	                details.addCell(arriveAmountBackValue);
	
	                PdfPCell batchNoValue = new PdfPCell(new Phrase(storageRecordDetail.getBatchNo(), fontEN));
	//              batchNoValue.setBorder(0);
	                batchNoValue.setBorderWidthTop(0);
	                batchNoValue.setBorderWidthBottom(0);
	                batchNoValue.setBorderWidthLeft(0);
	                details.addCell(batchNoValue);
	
	                details.completeRow();
	                //第一行结束
	 
	                PdfPCell itemDescribeValue = new PdfPCell(new Phrase(storageRecordDetail.getItemName(), fontCN));
	//              itemDescribeValue.setBorder(0);
	                itemDescribeValue.setBorderWidthTop(0);
	                itemDescribeValue.setBorderWidthLeft(0);
	                itemDescribeValue.setBorderWidthBottom(0);
	                itemDescribeValue.setColspan(3);
	                details.addCell(itemDescribeValue);
	
	
	                PdfPCell itemAmountValue = new PdfPCell(new Phrase(storageRecordDetail.getItemAmount().toString(), fontEN));
	//                itemAmountValue.setBorder(0);
	                itemAmountValue.setBorderWidthTop(0);
	                itemAmountValue.setBorderWidthLeft(0);
	                itemAmountValue.setBorderWidthBottom(0);
	                itemAmountValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
	                details.addCell(itemAmountValue);
	
	                PdfPCell pieceQuantityValue = new PdfPCell(new Phrase(storageRecordDetail.getPieceQuantity().toString(), fontEN));
	//                pieceQuantityValue.setBorder(0);
	                pieceQuantityValue.setBorderWidthTop(0);
	                pieceQuantityValue.setBorderWidthLeft(0);
	                pieceQuantityValue.setBorderWidthBottom(0);
	                pieceQuantityValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
	                details.addCell(pieceQuantityValue);
	
	              PdfPCell orderAmountOldsValue = new PdfPCell(new Phrase(storageRecordDetail.getOrderAmountOld().toString(), fontEN));
	//              orderAmountOldsValue.setBorder(0);
	              orderAmountOldsValue.setBorderWidthTop(0);
	              orderAmountOldsValue.setBorderWidthLeft(0);
	              orderAmountOldsValue.setBorderWidthBottom(0);
	              orderAmountOldsValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
	              details.addCell(orderAmountOldsValue);
	
	              PdfPCell tbatchDescribeValue = new PdfPCell(new Phrase(storageRecordDetail.getBatchDescribe(), fontCN));
	//              tbatchDescribeValue.setBorder(0);
	              tbatchDescribeValue.setBorderWidthTop(0);
	              tbatchDescribeValue.setBorderWidthLeft(0);
	              tbatchDescribeValue.setBorderWidthBottom(0);
	              tbatchDescribeValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
	              details.addCell(tbatchDescribeValue);
	
	              details.completeRow();
	              //第二行结束
	
	              PdfPCell itemPropertyValue = new PdfPCell(new Phrase(storageRecordDetail.getItemProperty(), fontCN));
	//              itemPropertyValue.setBorder(0);
	              itemPropertyValue.setBorderWidthTop(0);
	              itemPropertyValue.setBorderWidthLeft(0);
	              itemPropertyValue.setBorderWidthBottom(0);
	              itemPropertyValue.setBorderWidthRight(0);
	              itemPropertyValue.setColspan(2);
	              details.addCell(itemPropertyValue);
	
	              PdfPCell unitNameValue = new PdfPCell(new Phrase(storageRecordDetail.getUnitName(), fontCN));
	//              unitNameValue.setBorder(0);
	              unitNameValue.setBorderWidthTop(0);
	              unitNameValue.setBorderWidthLeft(0);
	              unitNameValue.setBorderWidthBottom(0);
	              unitNameValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
	              details.addCell(unitNameValue);
	
	              PdfPCell ullageAmountValue = new PdfPCell(new Phrase(storageRecordDetail.getUllageAmount().toString(), fontEN));
	//              ullageAmountValue.setBorder(0);
	              ullageAmountValue.setBorderWidthTop(0);
	              ullageAmountValue.setBorderWidthLeft(0);
	              ullageAmountValue.setBorderWidthBottom(0);
	              ullageAmountValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
	              details.addCell(ullageAmountValue);
	
	              PdfPCell itemPriceValue = new PdfPCell(new Phrase(storageRecordDetail.getItemPrice().toString(), fontEN));
	//              itemPriceValue.setBorder(0);
	              itemPriceValue.setBorderWidthTop(0);
	              itemPriceValue.setBorderWidthLeft(0);
	              itemPriceValue.setBorderWidthBottom(0);
	              itemPriceValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
	              details.addCell(itemPriceValue);
	
	              PdfPCell orderAmountTaxValue = new PdfPCell(new Phrase(storageRecordDetail.getOrderAmountTax().toString(), fontEN));
	//              orderAmountTaxValue.setBorder(0);
	              orderAmountTaxValue.setBorderWidthTop(0);
	              orderAmountTaxValue.setBorderWidthLeft(0);
	              orderAmountTaxValue.setBorderWidthBottom(0);
	              orderAmountTaxValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
	              details.addCell(orderAmountTaxValue);
	
	              PdfPCell commentssValue = new PdfPCell(new Phrase(storageRecordDetail.getComments(), fontCN));
	//              commentssValue.setBorder(0);
	              commentssValue.setBorderWidthTop(0);
	              commentssValue.setBorderWidthLeft(0);
	              commentssValue.setRowspan(2);
	              details.addCell(commentssValue);
	
	              details.completeRow();
	              //第三行结束
	              
	
	              PdfPCell floorNoValue = new PdfPCell(new Phrase(storageRecordDetail.getFloorNo(), fontCN));
	//              floorNoValue.setBorder(0);
	              floorNoValue.setBorderWidthTop(0);
	              floorNoValue.setBorderWidthLeft(0);
	              floorNoValue.setBorderWidthRight(0);
	              floorNoValue.setColspan(2);
	              details.addCell(floorNoValue);
	
	              PdfPCell storageNoValue = new PdfPCell(new Phrase(storageRecordDetail.getStorageNo(), fontEN));
	//              storageNoValue.setBorder(0);
	              storageNoValue.setBorderWidthTop(0);
	              storageNoValue.setBorderWidthLeft(0);
	              storageNoValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
	              details.addCell(storageNoValue);
	
	              PdfPCell wasterAmountValue = new PdfPCell(new Phrase(storageRecordDetail.getWasterAmount().toString(), fontEN));
	//              wasterAmountValue.setBorder(0);
	              wasterAmountValue.setBorderWidthTop(0);
	              wasterAmountValue.setBorderWidthLeft(0);
	              wasterAmountValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
	              details.addCell(wasterAmountValue);
	
	              PdfPCell orderAmountValue = new PdfPCell(new Phrase(storageRecordDetail.getOrderAmount().toString(), fontEN));
	//              orderAmountValue.setBorder(0);
	              orderAmountValue.setBorderWidthTop(0);
	              orderAmountValue.setBorderWidthLeft(0);
	              orderAmountValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
	              details.addCell(orderAmountValue);
	
	              PdfPCell orderAmountTotalValue = new PdfPCell(new Phrase(storageRecordDetail.getOrderAmountTotal().toString(), fontEN));
	//              orderAmountTotalValue.setBorder(0);
	              orderAmountTotalValue.setBorderWidthTop(0);
	              orderAmountTotalValue.setBorderWidthLeft(0);
	              orderAmountTotalValue.setHorizontalAlignment(Element.ALIGN_RIGHT);
	              details.addCell(orderAmountTotalValue);
	
	              details.completeRow();
	              //第四行结束
	              
	            }
	            
	            doc.add(details);
	      	
	        }
	        ////////////////////////////////////////////////////////////////////////////////////////////
	        
	//	    doc.add(line);
	
		    
	        PdfPTable masterFoot = new PdfPTable(8);
	        
	        masterFoot.setTotalWidth(new float[]{45, 85, 45, 85, 45, 85, 45, 85});
	        masterFoot.setLockedWidth(true);
	//        masterFoot.setSpacingBefore(10);
	
	        PdfPCell detailsCountCell = new PdfPCell(new Phrase("笔数:", fontCN));
	//        detailsCountCell.setBorder(0);
	        detailsCountCell.setBorderWidthTop(0);
	        detailsCountCell.setBorderWidthBottom(0);
	        detailsCountCell.setBorderWidthRight(0);
	        masterFoot.addCell(detailsCountCell);
	
	        PdfPCell detailsCountValue = new PdfPCell(new Phrase(String.valueOf(storageRecord.getDetailsCount()), fontEN));
	        detailsCountValue.setBorder(0);
	        masterFoot.addCell(detailsCountValue);
	
	        PdfPCell r1emptyCell = new PdfPCell(new Phrase(""));
	//        r1emptyCell.setBorder(0);
	        r1emptyCell.setBorderWidthTop(0);
	        r1emptyCell.setBorderWidthBottom(0);
	        r1emptyCell.setBorderWidthLeft(0);
	        r1emptyCell.setColspan(6);
	        masterFoot.addCell(r1emptyCell);
	
	        //第一行结束
	        masterFoot.completeRow();
	
	        PdfPCell itemAmountCell = new PdfPCell(new Phrase("数量合计:", fontCN));
	//        itemAmountCell.setBorder(0);
	        itemAmountCell.setBorderWidthTop(0);
	        itemAmountCell.setBorderWidthRight(0);
	        masterFoot.addCell(itemAmountCell);
	
	        PdfPCell itemAmountValue = new PdfPCell(new Phrase(storageRecord.getItemAmount().toString(), fontEN));
	        itemAmountValue.setBorderWidthTop(0);
	        itemAmountValue.setBorderWidthLeft(0);
	        itemAmountValue.setBorderWidthRight(0);
	        masterFoot.addCell(itemAmountValue);
	
	        PdfPCell orderAmountOldCell = new PdfPCell(new Phrase("未税金额:", fontCN));
	        orderAmountOldCell.setBorderWidthTop(0);
	        orderAmountOldCell.setBorderWidthLeft(0);
	        orderAmountOldCell.setBorderWidthRight(0);
	        masterFoot.addCell(orderAmountOldCell);
	
	        PdfPCell orderAmountOldValue = new PdfPCell(new Phrase(storageRecord.getOrderAmountOld().toString(), fontEN));
	        orderAmountOldValue.setBorderWidthTop(0);
	        orderAmountOldValue.setBorderWidthLeft(0);
	        orderAmountOldValue.setBorderWidthRight(0);
	        masterFoot.addCell(orderAmountOldValue);
	
	        PdfPCell orderAmountTaxCell = new PdfPCell(new Phrase("税额:", fontCN));
	        orderAmountTaxCell.setBorderWidthTop(0);
	        orderAmountTaxCell.setBorderWidthLeft(0);
	        orderAmountTaxCell.setBorderWidthRight(0);
	        masterFoot.addCell(orderAmountTaxCell);
	
	        PdfPCell orderAmountTaxValue = new PdfPCell(new Phrase(storageRecord.getOrderAmountTax().toString(), fontEN));
	        orderAmountTaxValue.setBorderWidthTop(0);
	        orderAmountTaxValue.setBorderWidthLeft(0);
	        orderAmountTaxValue.setBorderWidthRight(0);
	        masterFoot.addCell(orderAmountTaxValue);
	
	        PdfPCell orderAmountTotalCell = new PdfPCell(new Phrase("价税合计:", fontCN));
	        orderAmountTotalCell.setBorderWidthTop(0);
	        orderAmountTotalCell.setBorderWidthLeft(0);
	        orderAmountTotalCell.setBorderWidthRight(0);
	        masterFoot.addCell(orderAmountTotalCell);
	
	        PdfPCell orderAmountTotalValue = new PdfPCell(new Phrase(storageRecord.getOrderAmountTotal().toString(), fontEN));
	//        orderAmountTotalValue.setBorder(0);
	        orderAmountTotalValue.setBorderWidthTop(0);
	        orderAmountTotalValue.setBorderWidthLeft(0);
	        masterFoot.addCell(orderAmountTotalValue);
	
	        //第二行结束
	        masterFoot.completeRow();
	
	
	        doc.add(masterFoot);
	        
	        
	        
		    
	        PdfPTable masterTail = new PdfPTable(8);
	        
	        masterTail.setTotalWidth(new float[]{45, 65, 45, 105, 45, 65, 45, 105});
	        masterTail.setLockedWidth(true);
	        masterTail.setSpacingBefore(10);
	
	        PdfPCell cUsernameCell = new PdfPCell(new Phrase("制单:", fontCN));
	        cUsernameCell.setBorder(0);
	        masterTail.addCell(cUsernameCell);
	
	        PdfPCell cUsernameValue = new PdfPCell(new Phrase(storageRecord.getcUsername(), fontCN));
	        cUsernameValue.setBorder(0);
	        masterTail.addCell(cUsernameValue);
	
	        PdfPCell cDatetimeCell = new PdfPCell(new Phrase("制单时间:", fontCN));
	        cDatetimeCell.setBorder(0);
	        masterTail.addCell(cDatetimeCell);
	
	        PdfPCell cDatetimeValue = new PdfPCell(new Phrase(storageRecord.getcDatetime().toString(), fontEN));
	        cDatetimeValue.setBorder(0);
	        masterTail.addCell(cDatetimeValue);
	
	        PdfPCell tUsernameCell = new PdfPCell(new Phrase("审核:", fontCN));
	        tUsernameCell.setBorder(0);
	        masterTail.addCell(tUsernameCell);
	
	        PdfPCell tUsernameValue = new PdfPCell(new Phrase(storageRecord.gettUsername(), fontCN));
	        tUsernameValue.setBorder(0);
	        masterTail.addCell(tUsernameValue);
	
	        PdfPCell tDatetimeCell = new PdfPCell(new Phrase("审核时间:", fontCN));
	        tDatetimeCell.setBorder(0);
	        masterTail.addCell(tDatetimeCell);
	
	        PdfPCell tDatetimeValue = new PdfPCell(new Phrase(storageRecord.gettDatetime()==null?"":storageRecord.gettDatetime().toString(), fontEN));
	        tDatetimeValue.setBorder(0);
	        masterTail.addCell(tDatetimeValue);
	
	
	        masterTail.completeRow();
	        
	
	        doc.add(masterTail);
		    
	        Chunk printTimeChunk = new Chunk("打印时间: ",fontCN);
	        String printTime = Utils.getCurrentDateTime().toString();
	        Paragraph printTimeParagraph = new Paragraph(printTimeChunk);
	        Chunk printTimeValueChunk = new Chunk(printTime,fontEN);
	        printTimeParagraph.add(printTimeValueChunk);
	        printTimeParagraph.setAlignment(Element.ALIGN_RIGHT);
		    doc.add(printTimeParagraph);
	
		    
	//	    doc.close();
		    
		    
		    
	//        int pageNumber = doc.getPageNumber();
	//        System.out.println(pageNumber);
	//	    Rectangle rect = doc.getPageSize();
	//	    System.out.println("rect.getHeight()-->"+rect.getHeight());
	//	    System.out.println("rect.getWidth()-->"+rect.getWidth());
	//	    System.out.println("rect.getLeft()-->"+rect.getLeft());
	//	    System.out.println("rect.getTop()-->"+rect.getTop());
	//	    System.out.println("rect.getBottom()-->"+rect.getBottom());
	//	    System.out.println("rect.getRight()-->"+rect.getRight());
	//	    System.out.println("rect.getBorder()-->"+rect.getBorder());
	//	    System.out.println("rect.getBorderWidth()-->"+rect.getBorderWidth());
	//	    System.out.println("rect.getBorderWidthTop()-->"+rect.getBorderWidthTop());
	//	    System.out.println("rect.getBorderWidthLeft()-->"+rect.getBorderWidthLeft());
	//	    System.out.println("rect.getBorderWidthBottom()-->"+rect.getBorderWidthBottom());
	//	    System.out.println("rect.getBorderWidthRight()-->"+rect.getBorderWidthRight());
	
		}

		

}
